Skip to content

Commit

Permalink
Issue #61: failing test for TransactionObserver with several identica…
Browse files Browse the repository at this point in the history
…lly named savepoints
  • Loading branch information
groue committed May 28, 2016
1 parent 34dad07 commit a26bef8
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,48 @@ class TransactionObserverSavepointsTests: GRDBTestCase {
}
}

func testSavepointWithIdenticalName() {
assertNoError {
let dbQueue = try makeDatabaseQueue()
let observer = TransactionObserver()
dbQueue.addTransactionObserver(observer)

try dbQueue.inDatabase { db in
try db.execute("CREATE TABLE items1 (id INTEGER PRIMARY KEY)")
try db.execute("CREATE TABLE items2 (id INTEGER PRIMARY KEY)")
try db.execute("CREATE TABLE items3 (id INTEGER PRIMARY KEY)")
try db.execute("CREATE TABLE items4 (id INTEGER PRIMARY KEY)")
try db.execute("BEGIN TRANSACTION")
try db.execute("INSERT INTO items1 (id) VALUES (NULL)")
XCTAssertEqual(observer.events.count, 1)
try db.execute("SAVEPOINT sp1")
try db.execute("INSERT INTO items2 (id) VALUES (NULL)")
XCTAssertEqual(observer.events.count, 1)
try db.execute("SAVEPOINT sp1")
try db.execute("INSERT INTO items3 (id) VALUES (NULL)")
XCTAssertEqual(observer.events.count, 1)
try db.execute("RELEASE SAVEPOINT sp1")
XCTAssertEqual(observer.events.count, 1)
try db.execute("RELEASE SAVEPOINT sp1")
XCTAssertEqual(observer.events.count, 3)
try db.execute("INSERT INTO items4 (id) VALUES (NULL)")
XCTAssertEqual(observer.events.count, 4)
try db.execute("COMMIT")

XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items1"), 1)
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items2"), 1)
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items3"), 1)
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items4"), 1)
}

XCTAssertEqual(observer.lastCommittedEvents.count, 3)
XCTAssertTrue(match(event: observer.lastCommittedEvents[0], kind: .Insert, tableName: "items1", rowId: 1))
XCTAssertTrue(match(event: observer.lastCommittedEvents[1], kind: .Insert, tableName: "items2", rowId: 1))
XCTAssertTrue(match(event: observer.lastCommittedEvents[2], kind: .Insert, tableName: "items3", rowId: 1))
XCTAssertTrue(match(event: observer.lastCommittedEvents[3], kind: .Insert, tableName: "items4", rowId: 1))
}
}

func testRollbackNestedSavepoint() {
assertNoError {
let dbQueue = try makeDatabaseQueue()
Expand Down

0 comments on commit a26bef8

Please sign in to comment.