Skip to content

Commit

Permalink
Issue #61: fix failing test for TransactionObserver and savepoints
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed May 28, 2016
1 parent a26bef8 commit ad8551b
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class TransactionObserverSavepointsTests: GRDBTestCase {
try db.execute("INSERT INTO items2 (id) VALUES (NULL)")
XCTAssertEqual(observer.events.count, 0)
try db.execute("RELEASE SAVEPOINT sp1")
XCTAssertEqual(observer.events.count, 2)
XCTAssertFalse(db.isInsideTransaction)

XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items1"), 1)
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items2"), 1)
Expand Down Expand Up @@ -136,15 +138,15 @@ class TransactionObserverSavepointsTests: GRDBTestCase {
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items4"), 1)
}

XCTAssertEqual(observer.lastCommittedEvents.count, 3)
XCTAssertEqual(observer.lastCommittedEvents.count, 4)
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() {
func testMultipleRollbackOfSavepoint() {
assertNoError {
let dbQueue = try makeDatabaseQueue()
let observer = TransactionObserver()
Expand All @@ -165,7 +167,10 @@ class TransactionObserverSavepointsTests: GRDBTestCase {
XCTAssertEqual(observer.events.count, 1)
try db.execute("ROLLBACK TO SAVEPOINT sp1")
try db.execute("INSERT INTO items4 (id) VALUES (NULL)")
XCTAssertEqual(observer.events.count, 2)
XCTAssertEqual(observer.events.count, 1)
try db.execute("ROLLBACK TO SAVEPOINT sp1")
try db.execute("INSERT INTO items4 (id) VALUES (NULL)")
XCTAssertEqual(observer.events.count, 1)
try db.execute("COMMIT")

XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items1"), 1)
Expand All @@ -180,7 +185,7 @@ class TransactionObserverSavepointsTests: GRDBTestCase {
}
}

func testReleaseNestedSavepoint() {
func testReleaseSavepoint() {
assertNoError {
let dbQueue = try makeDatabaseQueue()
let observer = TransactionObserver()
Expand Down Expand Up @@ -243,7 +248,7 @@ class TransactionObserverSavepointsTests: GRDBTestCase {
try db.execute("ROLLBACK TO SAVEPOINT sp1")
XCTAssertEqual(observer.events.count, 1)
try db.execute("INSERT INTO items4 (id) VALUES (NULL)")
XCTAssertEqual(observer.events.count, 2)
XCTAssertEqual(observer.events.count, 1)
try db.execute("COMMIT")

XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items1"), 1)
Expand All @@ -254,7 +259,7 @@ class TransactionObserverSavepointsTests: GRDBTestCase {

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

Expand Down

0 comments on commit ad8551b

Please sign in to comment.