Repository navigation
Static shared connection following old example doesn't work nicely with tests. #3148
Unanswered
leuchthelp
asked this question in
Q&A
Replies: 3 comments
|
oh and here is the log running 4 tests
2026-07-24T13:14:19.229130Z INFO sqlx::query: summary="PRAGMA foreign_keys = ON; …" db.statement="\n\nPRAGMA foreign_keys = ON; \n" rows_affected=0 rows_returned=0 elapsed=30.197µs elapsed_secs=3.0197e-5
2026-07-24T13:14:19.229342Z INFO sqlx::query: summary="SELECT sqlite_version()" db.statement="" rows_affected=0 rows_returned=1 elapsed=72.906µs elapsed_secs=7.2906e-5
2026-07-24T13:14:19.229691Z INFO sqlx::query: summary="SELECT \"name\" FROM \"sqlite_master\" …" db.statement="\n\nSELECT \"name\" FROM \"sqlite_master\" WHERE \"type\" = ? AND \"name\" <> ?\n" rows_affected=0 rows_returned=0 elapsed=61.314µs elapsed_secs=6.1314e-5
2026-07-24T13:14:19.229806Z INFO sqlx::query: summary="SELECT \"name\" FROM \"sqlite_master\" …" db.statement="\n\nSELECT \"name\" FROM \"sqlite_master\" WHERE \"type\" = ? AND \"name\" <> ?\n" rows_affected=0 rows_returned=0 elapsed=5.15µs elapsed_secs=5.15e-6
2026-07-24T13:14:19.230044Z INFO sqlx::query: summary="CREATE TABLE \"providers\" ( …" db.statement="\n\nCREATE TABLE \"providers\" ( \"server_id\" uuid_text NOT NULL PRIMARY KEY, \"user_id\" uuid_text NOT NULL UNIQUE, \"kind\" varchar NOT NULL, \"url\" varchar NOT NULL )\n" rows_affected=0 rows_returned=0 elapsed=98.894µs elapsed_secs=9.8894e-5
2026-07-24T13:14:19.230231Z INFO sqlx::query: summary="CREATE TABLE \"media_items\" ( …" db.statement="\n\nCREATE TABLE \"media_items\" ( \"uuid\" uuid_text NOT NULL PRIMARY KEY UNIQUE, \"kind\" varchar NOT NULL, \"outline_gradient\" varchar NOT NULL, \"loaded\" boolean NOT NULL, \"local\" varchar NOT NULL )\n" rows_affected=0 rows_returned=0 elapsed=79.338µs elapsed_secs=7.9338e-5
2026-07-24T13:14:19.230419Z INFO sqlx::query: summary="CREATE TABLE \"content\" ( …" db.statement="\n\nCREATE TABLE \"content\" ( \"id\" integer NOT NULL PRIMARY KEY AUTOINCREMENT, \"parent_id\" uuid_text, \"kind\" varchar NOT NULL UNIQUE, \"description\" varchar NOT NULL, FOREIGN KEY (\"parent_id\") REFERENCES \"media_items\" (\"uuid\") )\n" rows_affected=0 rows_returned=0 elapsed=99.616µs elapsed_secs=9.9616e-5
2026-07-24T13:14:19.230610Z INFO sqlx::query: summary="CREATE TABLE \"jt_media_item_to_provider\" ( …" db.statement="\n\nCREATE TABLE \"jt_media_item_to_provider\" ( \"media_item_id\" uuid_text NOT NULL, \"provider_id\" uuid_text NOT NULL, CONSTRAINT \"pk-jt_media_item_to_provider\" PRIMARY KEY (\"media_item_id\", \"provider_id\"), FOREIGN KEY (\"media_item_id\") REFERENCES \"media_items\" (\"uuid\"), FOREIGN KEY (\"provider_id\") REFERENCES \"providers\" (\"user_id\") )\n" rows_affected=0 rows_returned=0 elapsed=88.505µs elapsed_secs=8.8505e-5
2026-07-24T13:14:19.230805Z INFO sqlx::query: summary="CREATE TABLE \"images\" ( …" db.statement="\n\nCREATE TABLE \"images\" ( \"url\" varchar NOT NULL PRIMARY KEY UNIQUE, \"server_id\" uuid_text, \"kind\" varchar NOT NULL, FOREIGN KEY (\"server_id\") REFERENCES \"providers\" (\"server_id\") )\n" rows_affected=0 rows_returned=0 elapsed=86.041µs elapsed_secs=8.6041e-5
2026-07-24T13:14:19.231025Z INFO sqlx::query: summary="CREATE TABLE \"jt_media_item_to_image\" ( …" db.statement="\n\nCREATE TABLE \"jt_media_item_to_image\" ( \"media_item_id\" uuid_text NOT NULL, \"image_url\" varchar NOT NULL, CONSTRAINT \"pk-jt_media_item_to_image\" PRIMARY KEY (\"media_item_id\", \"image_url\"), FOREIGN KEY (\"media_item_id\") REFERENCES \"media_items\" (\"uuid\"), FOREIGN KEY (\"image_url\") REFERENCES \"images\" (\"url\") )\n" rows_affected=0 rows_returned=0 elapsed=84.217µs elapsed_secs=8.4217e-5
2026-07-24T13:14:19.231189Z INFO sqlx::query: summary="CREATE TABLE \"original\" ( …" db.statement="\n\nCREATE TABLE \"original\" ( \"id\" integer NOT NULL PRIMARY KEY AUTOINCREMENT, \"parent_id\" uuid_text, \"server_id\" uuid_text NOT NULL, \"uuid\" uuid_text NOT NULL, \"url\" varchar NOT NULL UNIQUE, FOREIGN KEY (\"parent_id\") REFERENCES \"media_items\" (\"uuid\") )\n" rows_affected=0 rows_returned=0 elapsed=70.973µs elapsed_secs=7.0973e-5
2026-07-24T13:14:19.231355Z INFO sqlx::query: summary="CREATE TABLE \"jt_parent_to_child\" ( …" db.statement="\n\nCREATE TABLE \"jt_parent_to_child\" ( \"parent_id\" uuid_text NOT NULL, \"child_id\" uuid_text NOT NULL, CONSTRAINT \"pk-jt_parent_to_child\" PRIMARY KEY (\"parent_id\", \"child_id\"), FOREIGN KEY (\"parent_id\") REFERENCES \"media_items\" (\"uuid\"), FOREIGN KEY (\"child_id\") REFERENCES \"media_items\" (\"uuid\") )\n" rows_affected=0 rows_returned=0 elapsed=71.083µs elapsed_secs=7.1083e-5
test provider_manager::provider_manager_test::hash_no_login_failure ... ok
test jellyfin::jellyfin_provider::variant_jellyfin::matching_name ... ok
2026-07-24T13:14:19.390605Z INFO sqlx::query: summary="INSERT INTO \"providers\" (\"server_id\", …" db.statement="\n\nINSERT INTO \"providers\" (\"server_id\", \"user_id\", \"kind\", \"url\") VALUES (?, ?, ?, ?) RETURNING \"server_id\", \"user_id\", \"kind\", \"url\"\n" rows_affected=0 rows_returned=1 elapsed=100.247µs elapsed_secs=0.000100247
2026-07-24T13:14:19.391889Z INFO sqlx::query: summary="DELETE FROM \"providers\" WHERE …" db.statement="\n\nDELETE FROM \"providers\" WHERE \"providers\".\"user_id\" = ?\n" rows_affected=1 rows_returned=0 elapsed=39.354µs elapsed_secs=3.9354e-5
test provider_manager::provider_manager_test::try_provider_manager_flow ... ok
2026-07-24T13:14:19.554617Z INFO sqlx::query: summary="PRAGMA foreign_keys = ON; …" db.statement="\n\nPRAGMA foreign_keys = ON; \n" rows_affected=0 rows_returned=0 elapsed=24.296µs elapsed_secs=2.4296e-5
2026-07-24T13:14:19.554769Z INFO sqlx::query: summary="INSERT INTO \"providers\" (\"server_id\", …" db.statement="\n\nINSERT INTO \"providers\" (\"server_id\", \"user_id\", \"kind\", \"url\") VALUES (?, ?, ?, ?) RETURNING \"server_id\", \"user_id\", \"kind\", \"url\"\n" rows_affected=0 rows_returned=0 elapsed=66.134µs elapsed_secs=6.6134e-5
thread 'jellyfin::jellyfin_provider::variant_jellyfin::try_auth_flow' (149675) panicked at journey-provider/src/jellyfin/jellyfin_provider.rs:232:14:
called `Result::unwrap()` on an `Err` value: DbError(Query(SqlxError(Database(SqliteError { code: 1, message: "no such table: providers" }))))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test jellyfin::jellyfin_provider::variant_jellyfin::try_auth_flow ... FAILED
failures:
failures:
jellyfin::jellyfin_provider::variant_jellyfin::try_auth_flow
test result: FAILED. 3 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.33s
error: test failed, to rerun pass `-p journey-provider --lib` |
0 replies
|
This is because the connection is dropped after the test ends. Therefore, the sqlite in memory is also dropped (because there is no connection). Subsequent tests will recreate a one. |
0 replies
|
Assumed as much, so this kind on approach just simply doesn’t work for tests I guess. Interesting thought that the |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hey there, proper channel this time.
I've found this older guide from the cookbook on how to establish a single static connection, which can be shared.
I'm having a little issue with 2 of my current test. Both are setup as:
Where both have to perform functions that can only be setup once & therefore have to run in serial. For this I use the serial_test crate.
The connection is setup as follows:
Each test calls the
init_db()function once, since I can really control the order of serial execution, only that it will execute in serial. Therefore I check if theOnceCellhas already been initialized to avoid an unnecessary panic.This works and from the logs I can see that only one function actually sets up the
entity firstflow.However, once it actually reaches a point where an insert happens on the test that actually has performed the entity registration has actually created the database with all entities, which is usually the one that executes first. The other test does not get access to the same database or rather it does not have the same database as all tables seem to be missing.
If I run both tests individually, not within the same
cargo test -- --test <name>run, both work as they should with no errors.So the
tokio::OnceCellportion works when running the same function for both tests. The cell gets populated as otherwise theinit_db()function would panic / throw an error, but the actuallydatabasewas only created for one of the tests calling the function.Is this guide still up to date or rather how could I test this properly, since it seems I'm doing something wrong?
Thanks in advance.
All reactions