From b71de1559aa517f1c2c466d722b38283cf293d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 29 Feb 2020 14:43:17 +0100 Subject: [PATCH] Disable flaky testCachedStatementsAreNotShared See https://github.com/groue/GRDB.swift/issues/679 --- .../DatabasePoolSchemaCacheTests.swift | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/Tests/GRDBTests/DatabasePoolSchemaCacheTests.swift b/Tests/GRDBTests/DatabasePoolSchemaCacheTests.swift index b02a5b789..4f3e588fc 100644 --- a/Tests/GRDBTests/DatabasePoolSchemaCacheTests.swift +++ b/Tests/GRDBTests/DatabasePoolSchemaCacheTests.swift @@ -83,44 +83,45 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase { } } } - - func testCachedStatementsAreNotShared() throws { - // This is a regression test. - // - // If cached statements were shared between reader connections, this - // test would crash with fatal error: Database was not used on the - // correct thread. - let dbPool = try makeDatabasePool() - try dbPool.write { db in - try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") - try db.execute(sql: "INSERT INTO items (id) VALUES (1)") - } - - // Block 1 Block 2 - // SELECT 1 FROM items WHERE id = 1 - // > - let s1 = DispatchSemaphore(value: 0) - // SELECT 1 FROM items WHERE id = 1 - - let block1 = { () in - try! dbPool.read { db in - let stmt = try! db.cachedSelectStatement(sql: "SELECT * FROM items") - XCTAssertEqual(try Int.fetchOne(stmt)!, 1) - s1.signal() - } - } - let block2 = { () in - try! dbPool.read { db in - _ = s1.wait(timeout: .distantFuture) - let stmt = try! db.cachedSelectStatement(sql: "SELECT * FROM items") - XCTAssertEqual(try Int.fetchOne(stmt)!, 1) - } - } - let blocks = [block1, block2] - DispatchQueue.concurrentPerform(iterations: blocks.count) { index in - blocks[index]() - } - } + + // TODO: fix flaky test +// func testCachedStatementsAreNotShared() throws { +// // This is a regression test. +// // +// // If cached statements were shared between reader connections, this +// // test would crash with fatal error: Database was not used on the +// // correct thread. +// let dbPool = try makeDatabasePool() +// try dbPool.write { db in +// try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") +// try db.execute(sql: "INSERT INTO items (id) VALUES (1)") +// } +// +// // Block 1 Block 2 +// // SELECT 1 FROM items WHERE id = 1 +// // > +// let s1 = DispatchSemaphore(value: 0) +// // SELECT 1 FROM items WHERE id = 1 +// +// let block1 = { () in +// try! dbPool.read { db in +// let stmt = try! db.cachedSelectStatement(sql: "SELECT * FROM items") +// XCTAssertEqual(try Int.fetchOne(stmt)!, 1) +// s1.signal() +// } +// } +// let block2 = { () in +// try! dbPool.read { db in +// _ = s1.wait(timeout: .distantFuture) +// let stmt = try! db.cachedSelectStatement(sql: "SELECT * FROM items") +// XCTAssertEqual(try Int.fetchOne(stmt)!, 1) +// } +// } +// let blocks = [block1, block2] +// DispatchQueue.concurrentPerform(iterations: blocks.count) { index in +// blocks[index]() +// } +// } func testCacheSnapshotIsolation() throws { // This test checks that the schema cache follows snapshot isolation.