mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-24 04:07:47 +00:00
Make all ValueObservation tests deterministic (avoid inverted expectations)
Inverted expectations were just too flaky on Travis
This commit is contained in:
1 parent
f09a62415d
commit
425e506862
5 files changed
+42
-17
No files matched your search
@@ -7,7 +7,7 @@ class ValueObservationCountTests: GRDBTestCase {
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.tracking(T.fetchCount),
|
||||
records: [0, 1, 1, 2, 3, 2],
|
||||
records: [0, 1, 1, 2, 3, 4],
|
||||
setup: { db in
|
||||
try db.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)")
|
||||
},
|
||||
@@ -21,7 +21,7 @@ class ValueObservationCountTests: GRDBTestCase {
|
||||
try db.execute(sql: "DELETE FROM t WHERE id = 1")
|
||||
return .commit
|
||||
}
|
||||
try db.execute(sql: "DELETE FROM t WHERE id = 2")
|
||||
try db.execute(sql: "INSERT INTO t DEFAULT VALUES")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class ValueObservationCountTests: GRDBTestCase {
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.tracking(T.fetchCount).removeDuplicates(),
|
||||
records: [0, 1, 2, 3, 2],
|
||||
records: [0, 1, 2, 3, 4],
|
||||
setup: { db in
|
||||
try db.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)")
|
||||
},
|
||||
@@ -44,7 +44,7 @@ class ValueObservationCountTests: GRDBTestCase {
|
||||
try db.execute(sql: "DELETE FROM t WHERE id = 1")
|
||||
return .commit
|
||||
}
|
||||
try db.execute(sql: "DELETE FROM t WHERE id = 2")
|
||||
try db.execute(sql: "INSERT INTO t DEFAULT VALUES")
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,8 @@ class ValueObservationRecordTests: GRDBTestCase {
|
||||
Player(id: 1, name: "foo"),
|
||||
Player(id: 1, name: "foo"),
|
||||
Player(id: 2, name: "bar"),
|
||||
nil],
|
||||
nil,
|
||||
Player(id: 3, name: "toto")],
|
||||
setup: { db in
|
||||
try db.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
||||
},
|
||||
@@ -91,6 +92,7 @@ class ValueObservationRecordTests: GRDBTestCase {
|
||||
return .commit
|
||||
}
|
||||
try db.execute(sql: "DELETE FROM t")
|
||||
try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'toto')")
|
||||
})
|
||||
|
||||
// The fundamental technique for removing duplicates of non-Equatable types
|
||||
@@ -103,7 +105,8 @@ class ValueObservationRecordTests: GRDBTestCase {
|
||||
nil,
|
||||
Player(id: 1, name: "foo"),
|
||||
Player(id: 2, name: "bar"),
|
||||
nil],
|
||||
nil,
|
||||
Player(id: 3, name: "toto")],
|
||||
setup: { db in
|
||||
try db.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
||||
},
|
||||
@@ -117,6 +120,7 @@ class ValueObservationRecordTests: GRDBTestCase {
|
||||
return .commit
|
||||
}
|
||||
try db.execute(sql: "DELETE FROM t")
|
||||
try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'toto')")
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -459,17 +459,33 @@ extension GRDBTestCase {
|
||||
|
||||
try writer.writeWithoutTransaction(recordedUpdates)
|
||||
|
||||
let expectation = recorder
|
||||
.prefix(expectedValues.count + 2 /* pool may perform double initial fetch */)
|
||||
.inverted
|
||||
let values = try wait(for: expectation, timeout: 0.3)
|
||||
let recordedValues: [Reducer.Value]
|
||||
let lastExpectedValue = expectedValues.last!
|
||||
let waitForLast = expectedValues.firstIndex(of: lastExpectedValue) == expectedValues.count - 1
|
||||
if waitForLast {
|
||||
// Optimization!
|
||||
let expectation = recorder.prefix(until: { $0 == lastExpectedValue } )
|
||||
recordedValues = try wait(for: expectation, timeout: 1)
|
||||
} else {
|
||||
// Slow!
|
||||
assertionFailure("Please rewrite your test, because it is too slow: make sure the last expected value is unique.")
|
||||
let expectation = recorder
|
||||
.prefix(expectedValues.count + 2 /* pool may perform double initial fetch */)
|
||||
.inverted
|
||||
#if SQLITE_HAS_CODEC || GRDBCUSTOMSQLITE
|
||||
// debug SQLite builds can be *very* slow
|
||||
recordedValues = try wait(for: expectation, timeout: 1)
|
||||
#else
|
||||
recordedValues = try wait(for: expectation, timeout: 0.3)
|
||||
#endif
|
||||
}
|
||||
|
||||
if scheduler.immediateInitialValue() {
|
||||
XCTAssertEqual(values.first, expectedValues.first)
|
||||
XCTAssertEqual(recordedValues.first, expectedValues.first)
|
||||
}
|
||||
|
||||
assertValueObservationRecordingMatch(
|
||||
recorded: values,
|
||||
recorded: recordedValues,
|
||||
expected: expectedValues,
|
||||
"\(#function), \(writer), \(scheduler)", file: file, line: line)
|
||||
}
|
||||
@@ -506,6 +522,7 @@ extension GRDBTestCase {
|
||||
recordedValues = try wait(for: expectation, timeout: 1)
|
||||
} else {
|
||||
// Slow!
|
||||
assertionFailure("Please rewrite your test, because it is too slow: make sure the last expected value is unique.")
|
||||
let expectation = recorder
|
||||
.prefix(expectedValues.count + 2 /* pool may perform double initial fetch */)
|
||||
.inverted
|
||||
|
||||
@@ -61,7 +61,8 @@ class ValueObservationRowTests: GRDBTestCase {
|
||||
["id":1, "name":"foo"],
|
||||
["id":1, "name":"foo"],
|
||||
["id":2, "name":"bar"],
|
||||
nil],
|
||||
nil,
|
||||
["id":3, "name":"toto"]],
|
||||
setup: { db in
|
||||
try db.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
||||
},
|
||||
@@ -75,6 +76,7 @@ class ValueObservationRowTests: GRDBTestCase {
|
||||
return .commit
|
||||
}
|
||||
try db.execute(sql: "DELETE FROM t")
|
||||
try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'toto')")
|
||||
})
|
||||
|
||||
try assertValueObservation(
|
||||
@@ -83,7 +85,8 @@ class ValueObservationRowTests: GRDBTestCase {
|
||||
nil,
|
||||
["id":1, "name":"foo"],
|
||||
["id":2, "name":"bar"],
|
||||
nil],
|
||||
nil,
|
||||
["id":3, "name":"toto"]],
|
||||
setup: { db in
|
||||
try db.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
||||
},
|
||||
@@ -97,6 +100,7 @@ class ValueObservationRowTests: GRDBTestCase {
|
||||
return .commit
|
||||
}
|
||||
try db.execute(sql: "DELETE FROM t")
|
||||
try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'toto')")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
})
|
||||
|
||||
withExtendedLifetime(cancellable) {
|
||||
waitForExpectations(timeout: 0.3, handler: nil)
|
||||
waitForExpectations(timeout: 1, handler: nil)
|
||||
XCTAssertTrue(errorCaught)
|
||||
}
|
||||
}
|
||||
@@ -227,7 +227,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
try dbWriter.write { db in
|
||||
try db.execute(sql: "INSERT INTO t DEFAULT VALUES")
|
||||
}
|
||||
waitForExpectations(timeout: 0.2, handler: nil)
|
||||
waitForExpectations(timeout: 1, handler: nil)
|
||||
}
|
||||
|
||||
try test(makeDatabaseQueue())
|
||||
@@ -270,7 +270,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
try dbWriter.write { db in
|
||||
try db.execute(sql: "INSERT INTO t DEFAULT VALUES")
|
||||
}
|
||||
waitForExpectations(timeout: 0.2, handler: nil)
|
||||
waitForExpectations(timeout: 1, handler: nil)
|
||||
}
|
||||
|
||||
try test(makeDatabaseQueue())
|
||||
|
||||
Reference in new issue
Block a user