Skip to content

Commit ac2f2e8

Browse files
committed
Test that we recover from the FTS5 bug
1 parent e281149 commit ac2f2e8

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Tests/GRDBTests/Issue1838Tests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,30 @@ class Issue1838Tests: GRDBTestCase {
2424
}
2525
XCTAssertEqual(documentCount, 0)
2626
}
27+
28+
/// Tests about how we handle the FTS5 bug <https://sqlite.org/forum/forumpost/95413eb410>
29+
func test_interrupted_commit() throws {
30+
let dbQueue = try makeDatabaseQueue()
31+
32+
try dbQueue.write { db in
33+
try db.execute(sql: "CREATE VIRTUAL TABLE documents USING FTS5(content)")
34+
}
35+
36+
do {
37+
try dbQueue.write { db in
38+
try db.execute(sql: "INSERT INTO documents(content) VALUES ('Document')")
39+
dbQueue.interrupt()
40+
}
41+
// Do not assert that the above code throws, because the
42+
// FTS5 bug might be fixed in the tested SQLite version.
43+
} catch DatabaseError.SQLITE_INTERRUPT {
44+
// Fine: That's the FTS5 bug.
45+
}
46+
47+
// Make sure the interrupted state created by the FTS5 bug is no longer active.
48+
let documentCount = try dbQueue.read { db in
49+
try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents")!
50+
}
51+
XCTAssertEqual(documentCount, 0)
52+
}
2753
}

0 commit comments

Comments
 (0)