From 00e2c2a626fa42133d734e700b2037da797e2891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 2 Sep 2019 05:39:38 +0200 Subject: [PATCH] Fix testBarrierIsLockedByOneUnfinishedRead for Swift 4.2 --- .../DatabasePoolConcurrencyTests.swift | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift b/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift index 4abb7c433..e02486620 100644 --- a/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift +++ b/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift @@ -1244,29 +1244,36 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") } - // Read let s1 = DispatchSemaphore(value: 0) let s2 = DispatchSemaphore(value: 0) - dbPool.asyncRead { _ in - s1.signal() - s2.wait() + let s3 = DispatchSemaphore(value: 0) + let s4 = DispatchSemaphore(value: 0) + + DispatchQueue.global().async { + try! dbPool.read { _ in + s1.signal() + s2.signal() + s3.wait() + } } - let s3 = DispatchSemaphore(value: 0) DispatchQueue.global().async { + // Wait for read to start + s1.wait() + dbPool.barrierWriteWithoutTransaction { _ in } expectation.fulfill() - s3.signal() + s4.signal() } // Assert that barrier is blocked waitForExpectations(timeout: 1) // Release read - s2.signal() + s3.signal() // Wait for barrier to complete - s3.wait() + s4.wait() } } }