Code Monkey home page Code Monkey logo

Comments (3)

mharkins-cosm avatar mharkins-cosm commented on June 12, 2024 1

Thanks @patrickfreed for the feedback!

I'll see if I can figure out how to do the latter (single runtime for multithreaded tests), since that more closely resembles the webapp experience.

Really what I'm looking for is a way to access a static pool of connections in a multithreaded environment, without the overhead of reestablishing a connection each time I need one.

Re: a few other notes:

  • Good to know. I'll do away with the wrapping Arc
  • The purpose is along the lines of a singleton connection instance... trying to accomplish a shared connection (or pool) as mentioned.

Thanks again!

from mongo-rust-driver.

patrickfreed avatar patrickfreed commented on June 12, 2024

Each #[tokio::test] spins up its own runtime, so it's not possible to share the same client from each of them. Instead, I'd recommend creating a new client in each test. Alternatively, you can create a single runtime outside of the tests that is shared by each test, and annotate them with the regular #[test] instead.

A few other notes:
- Collection internally is just a wrapper around an Arc and is Clone, so you don't need to wrap it in an Arc
- It's not clear to me what the expected behavior of using futures::block_on in a static context is with the driver. I'd recommend instead awaiting the futures from within the context of a tokio runtime instead.

from mongo-rust-driver.

patrickfreed avatar patrickfreed commented on June 12, 2024

No problem, happy to help. Also, the Client type internally manages connection pools to each server in the deployment, so sharing one will indeed achieve the pooling behavior you're looking for (no need to pool the clients).

Going to go ahead and close this ticket, but please let us know if you have any further questions!

from mongo-rust-driver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.