Skip to content

Commit

Permalink
chore(sqlite): add repro for #1419
Browse files Browse the repository at this point in the history
  • Loading branch information
abonander committed Sep 22, 2021
1 parent 593364f commit ba3994e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
15 changes: 5 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions tests/sqlite/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,3 +567,54 @@ async fn concurrent_resets_dont_segfault() {

sqlx_rt::sleep(Duration::from_millis(1)).await;
}

// https://github.com/launchbadge/sqlx/issues/1419
// note: this passes before and after the fix; you need to run it with `--nocapture`
// to see the panic from the worker thread, which doesn't happen after the fix
#[sqlx_macros::test]
async fn row_dropped_after_connection_doesnt_panic() {
for _ in 0..2 {
let mut conn = SqliteConnection::connect(":memory:").await.unwrap();

conn.execute(
"CREATE TABLE IF NOT EXISTS books
(
title TEXT NOT NULL,
created_at INTEGER DEFAULT (cast(strftime('%s','now') as int)),
updated_at INTEGER DEFAULT (cast(strftime('%s','now') as int))
);
INSERT INTO books(title) VALUES('hello');
INSERT INTO books(title) VALUES('test');
INSERT INTO books(title) VALUES('example');
INSERT INTO books(title) VALUES('stuff');
INSERT INTO books(title) VALUES('here');
INSERT INTO books(title) VALUES('there');
INSERT INTO books(title) VALUES('everywhere');",
)
.await
.unwrap();

let books = sqlx::query("SELECT * FROM books")
.fetch_all(&mut conn)
.await
.unwrap();

for book in &books {
// force the row to be inflated
let title: String = book.get("title");

sqlx::query("DELETE FROM books WHERE title = ?")
.bind(&title)
.execute(&mut conn)
.await
.unwrap();
}

// hold `_books` past the lifetime of `conn`
drop(conn);
drop(books);

sqlx_rt::sleep(std::time::Duration::from_millis(50)).await
}
}

0 comments on commit ba3994e

Please sign in to comment.