Skip to content

Commit

Permalink
Updated the table lock policy test timings to attempt to stabilize CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnoon committed May 2, 2018
1 parent 6a26aae commit 6ca3601
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions Tests/Tests/Database/TableLockPolicyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,28 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {

// When
DispatchQueue.userInitiated.async {
print("Starting write")

do {
try TestTables.insertDummyAgents(count: 1_000, connection: writeConnection)
try TestTables.insertDummyAgents(count: 10_000, connection: writeConnection)
} catch {
writeError = error
}

print("Finished write")
writeExpectation.fulfill()
}

DispatchQueue.userInitiated.asyncAfter(seconds: 0.01) {
DispatchQueue.userInitiated.asyncAfter(seconds: 0.05) {
print("Starting read")

do {
readCount = try readConnection.query("SELECT count(*) FROM agents")
} catch {
readError = error
}

print("Finished read")
readExpectation.fulfill()
}

Expand Down Expand Up @@ -99,7 +105,7 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
sharedCache: true
)

try TestTables.insertDummyAgents(count: 1_000, connection: writeConnection)
try TestTables.insertDummyAgents(count: 5_000, connection: writeConnection)

let writeExpectation = self.expectation(description: "Write should fail")
let readExpectation = self.expectation(description: "Read should succeed")
Expand All @@ -119,9 +125,9 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
readExpectation.fulfill()
}

DispatchQueue.userInitiated.asyncAfter(seconds: 0.01) {
DispatchQueue.userInitiated.asyncAfter(seconds: 0.1) {
do {
try TestTables.insertDummyAgents(count: 1_000, connection: writeConnection)
try TestTables.insertDummyAgents(count: 5_000, connection: writeConnection)
} catch {
writeError = error
}
Expand All @@ -132,7 +138,7 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
waitForExpectations(timeout: timeout, handler: nil)

// Then
XCTAssertEqual(agents.count, 1_002)
XCTAssertEqual(agents.count, 5_002)
XCTAssertNil(readError)
XCTAssertNotNil(writeError)

Expand All @@ -156,7 +162,7 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
sharedCache: true
)

try TestTables.insertDummyAgents(count: 1_000, connection: writeConnection)
try TestTables.insertDummyAgents(count: 5_000, connection: writeConnection)

let writeExpectation = self.expectation(description: "Write should fail")
let readExpectation = self.expectation(description: "Read should succeed")
Expand All @@ -176,7 +182,7 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
readExpectation.fulfill()
}

DispatchQueue.userInitiated.asyncAfter(seconds: 0.01) {
DispatchQueue.userInitiated.asyncAfter(seconds: 0.1) {
do {
let dateString = bindingDateFormatter.string(from: Date())

Expand All @@ -196,7 +202,7 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
waitForExpectations(timeout: timeout, handler: nil)

// Then
XCTAssertEqual(agents.count, 1_002)
XCTAssertEqual(agents.count, 5_002)
XCTAssertNil(readError)
XCTAssertNotNil(writeError)

Expand Down Expand Up @@ -232,15 +238,15 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
// When
DispatchQueue.userInitiated.async {
do {
try TestTables.insertDummyAgents(count: 1_000, connection: writeConnection)
try TestTables.insertDummyAgents(count: 5_000, connection: writeConnection)
} catch {
writeError = error
}

writeExpectation.fulfill()
}

DispatchQueue.userInitiated.asyncAfter(seconds: 0.01) {
DispatchQueue.userInitiated.asyncAfter(seconds: 0.1) {
do {
readCount = try readConnection.query("SELECT count(*) FROM agents")
} catch {
Expand All @@ -255,7 +261,7 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
// Then
XCTAssertNil(writeError)
XCTAssertNil(readError)
XCTAssertEqual(readCount, 1_002)
XCTAssertEqual(readCount, 5_002)
}

func testThatConnectionDoesNotThrowErrorWhenReadLockBlocksWriteLockWithTableLockPolicyEnabled() throws {
Expand All @@ -273,7 +279,7 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
sharedCache: true
)

try TestTables.insertDummyAgents(count: 1_000, connection: writeConnection)
try TestTables.insertDummyAgents(count: 5_000, connection: writeConnection)

let writeExpectation = self.expectation(description: "Write should succeed")
let readExpectation = self.expectation(description: "Read should succeed")
Expand All @@ -293,9 +299,9 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
readExpectation.fulfill()
}

DispatchQueue.userInitiated.asyncAfter(seconds: 0.01) {
DispatchQueue.userInitiated.asyncAfter(seconds: 0.1) {
do {
try TestTables.insertDummyAgents(count: 1_000, connection: writeConnection)
try TestTables.insertDummyAgents(count: 5_000, connection: writeConnection)
} catch {
writeError = error
}
Expand All @@ -306,7 +312,7 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
waitForExpectations(timeout: timeout, handler: nil)

// Then
XCTAssertEqual(agents.count, 1_002)
XCTAssertEqual(agents.count, 5_002)
XCTAssertNil(readError)
XCTAssertNil(writeError)
}
Expand All @@ -326,7 +332,7 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
sharedCache: true
)

try TestTables.insertDummyAgents(count: 1_000, connection: writeConnection)
try TestTables.insertDummyAgents(count: 5_000, connection: writeConnection)

let writeExpectation = self.expectation(description: "Write should succeed")
let readExpectation = self.expectation(description: "Read should succeed")
Expand All @@ -346,7 +352,7 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
readExpectation.fulfill()
}

DispatchQueue.userInitiated.asyncAfter(seconds: 0.01) {
DispatchQueue.userInitiated.asyncAfter(seconds: 0.1) {
do {
let dateString = bindingDateFormatter.string(from: Date())

Expand All @@ -366,7 +372,7 @@ class TableLockPolicyTestCase: BaseConnectionTestCase {
waitForExpectations(timeout: timeout, handler: nil)

// Then
XCTAssertEqual(agents.count, 1_002)
XCTAssertEqual(agents.count, 5_002)
XCTAssertNil(readError)
XCTAssertNil(writeError)
}
Expand Down

0 comments on commit 6ca3601

Please sign in to comment.