Git Product home page Git Product logo

r2d2-sqlite's People

Contributors

gwenn avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

r2d2-sqlite's Issues

In memory connection pool not sharing state

Hi, I'm happily using Pool::new(SqliteConnectionManager::file(foo)) in my production code and everything is working fine.

However now I'm writing unit tests which I want to run on an in-memory instance of sqlite.

I create my connection pool like:

pub struct DbConnection(Pool<SqliteConnectionManager>);
impl DbConnection {
    pub fn test() -> Self {
        let manager = SqliteConnectionManager::memory();
        let pool = Pool::new(manager).unwrap();
        let db_conn = DbConnection(pool);
        db_conn.initialise().unwrap();
        db_conn
    }

   fn initialise(&self) -> Result<(), Error> {
        let conn = &*self.0.clone().get()?;
        conn.execute_batch("create table if not exists foo (...)")?;
        Ok(())
   }
}

and my unit tests (which just insert into that table) fail with "table foo does not exist".

If I instead change it to

        let manager = SqliteConnectionManager::memory();
        let pool = Pool::builder().max_size(1).build(manager).unwrap();

then my test passes. If I make that max_size(2) then it fails again.

The only conclusion I can come to is that when the initialisation and the test use the same connection then everything is fine, but if they use different ones then the test does not see the result of the initialisation call.
Is this intended? It seems like very surprising behaviour if so.

The full code can be found here: https://github.com/djmcgill/dominions-5-status/blob/master/src/db/mod.rs

P. S. I'm fairly new to Rust so if I'm using something unidiomatically please do let me know.

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.