Tests wait for expections on the MainActor

This commit is contained in:
Gwendal Roué committed 2024-02-18 12:41:34 +01:00
1 parent aadb76199b
commit 22a50a027a
7 files changed
+48

No files matched your search

@@ -21,6 +21,7 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
// MARK: -
@MainActor
func testReadPublisher() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -127,6 +128,7 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
// frame #70: 0x0000000100002f07 xctest`main + 210
// frame #71: 0x00007fff72311cc9 libdyld.dylib`start + 1
// frame #72: 0x00007fff72311cc9 libdyld.dylib`start + 1
@MainActor
func testReadPublisherError() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -156,6 +158,7 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
// MARK: -
@MainActor
func testReadPublisherIsAsynchronous() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -196,6 +199,7 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
// MARK: -
@MainActor
func testReadPublisherDefaultScheduler() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -236,6 +240,7 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
// MARK: -
@MainActor
func testReadPublisherCustomScheduler() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -277,6 +282,7 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
// MARK: -
@MainActor
func testReadPublisherIsReadonly() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -19,6 +19,7 @@ private struct Player: Codable, FetchableRecord, PersistableRecord {
class DatabaseRegionObservationPublisherTests : XCTestCase {
@MainActor
func testChangesNotifications() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -60,6 +61,7 @@ class DatabaseRegionObservationPublisherTests : XCTestCase {
//
// TODO: do the same, but asynchronously. If this is too hard, update the
// public API so that users can easily do it.
@MainActor
func testPrependInitialDatabaseSync() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -21,6 +21,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
// MARK: -
@MainActor
func testWritePublisher() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -48,6 +49,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
// MARK: -
@MainActor
func testWritePublisherValue() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -75,6 +77,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
// MARK: -
@MainActor
func testWritePublisherError() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -98,6 +101,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testWritePublisherErrorRollbacksTransaction() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -131,6 +135,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
// MARK: -
@MainActor
func testWritePublisherIsAsynchronous() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -167,6 +172,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
// MARK: -
@MainActor
func testWritePublisherDefaultScheduler() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -205,6 +211,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
// MARK: -
@MainActor
func testWritePublisherCustomScheduler() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -246,6 +253,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
// TODO: Fix flaky test with both pool and on-disk queue:
// - Expectation timeout
@MainActor
func testWriteThenReadPublisher() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -273,6 +281,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
// MARK: -
@MainActor
func testWriteThenReadPublisherIsReadonly() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -298,6 +307,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
// MARK: -
@MainActor
func testWriteThenReadPublisherWriteError() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -321,6 +331,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testWriteThenReadPublisherWriteErrorRollbacksTransaction() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -358,6 +369,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
// TODO: Fix flaky test with both pool and on-disk queue:
// - Expectation timeout
@MainActor
func testWriteThenReadPublisherReadError() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -385,6 +397,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
// Regression test against deadlocks created by concurrent completion
// and cancellations triggered by .switchToLatest().prefix(1)
@MainActor
func testDeadlockPrevention() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
+1
View File
@@ -3,6 +3,7 @@ import Combine
import Foundation
import XCTest
@MainActor
final class Test<Context> {
// Raise the repeatCount in order to help spotting flaky tests.
private let repeatCount: Int
@@ -21,6 +21,7 @@ class ValueObservationPublisherTests : XCTestCase {
// MARK: - Default Scheduler
@MainActor
func testDefaultSchedulerChangesNotifications() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -63,6 +64,7 @@ class ValueObservationPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
}
@MainActor
func testDefaultSchedulerFirstValueIsEmittedAsynchronously() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -96,6 +98,7 @@ class ValueObservationPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
}
@MainActor
func testDefaultSchedulerError() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -122,6 +125,7 @@ class ValueObservationPublisherTests : XCTestCase {
// MARK: - Immediate Scheduler
@MainActor
func testImmediateSchedulerChangesNotifications() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -164,6 +168,7 @@ class ValueObservationPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
}
@MainActor
func testImmediateSchedulerEmitsFirstValueSynchronously() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -200,6 +205,7 @@ class ValueObservationPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
}
@MainActor
func testImmediateSchedulerError() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -256,6 +262,7 @@ class ValueObservationPublisherTests : XCTestCase {
}
}
@MainActor
func testDemandNoneReceivesNoElement() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -291,6 +298,7 @@ class ValueObservationPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
}
@MainActor
func testDemandOneReceivesOneElement() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -329,6 +337,7 @@ class ValueObservationPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
}
@MainActor
func testDemandOneDoesNotReceiveTwoElements() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -371,6 +380,7 @@ class ValueObservationPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
}
@MainActor
func testDemandTwoReceivesTwoElements() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -417,6 +427,7 @@ class ValueObservationPublisherTests : XCTestCase {
// MARK: - Regression Tests
/// Regression test for https://github.com/groue/GRDB.swift/issues/1194
@MainActor
func testIssue1194() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -3,6 +3,7 @@ import GRDB
class DatabaseMigratorTests : GRDBTestCase {
@MainActor
func testEmptyMigratorSync() throws {
func test(writer: some DatabaseWriter) throws {
let migrator = DatabaseMigrator()
@@ -14,6 +15,7 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testEmptyMigratorAsync() throws {
func test(writer: some DatabaseWriter) throws {
let expectation = self.expectation(description: "")
@@ -34,6 +36,7 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testEmptyMigratorPublisher() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -51,6 +54,7 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testNonEmptyMigratorSync() throws {
func test(writer: some DatabaseWriter) throws {
var migrator = DatabaseMigrator()
@@ -95,6 +99,7 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testNonEmptyMigratorAsync() throws {
func test(writer: some DatabaseWriter) throws {
var migrator = DatabaseMigrator()
@@ -149,6 +154,7 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testNonEmptyMigratorPublisher() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -205,6 +211,7 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testEmptyMigratorPublisherIsAsynchronous() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -231,6 +238,7 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testNonEmptyMigratorPublisherIsAsynchronous() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -258,6 +266,7 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testMigratorPublisherDefaultScheduler() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -287,6 +296,7 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testMigratorPublisherCustomScheduler() throws {
guard #available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) else {
throw XCTSkip("Combine is not available")
@@ -317,6 +327,7 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testMigrateUpTo() throws {
func test(writer: some DatabaseWriter) throws {
var migrator = DatabaseMigrator()
@@ -368,6 +379,7 @@ class DatabaseMigratorTests : GRDBTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
@MainActor
func testMigrationFailureTriggersRollback() throws {
var migrator = DatabaseMigrator()
migrator.registerMigration("createPersons") { db in
@@ -1034,6 +1034,7 @@ class ValueObservationTests: GRDBTestCase {
}
// An attempt at finding a regression test for <https://github.com/groue/GRDB.swift/issues/1362>
@MainActor
func testManyObservations() throws {
// We'll start many observations
let observationCount = 100
@@ -1092,6 +1093,7 @@ class ValueObservationTests: GRDBTestCase {
}
// An attempt at finding a regression test for <https://github.com/groue/GRDB.swift/issues/1362>
@MainActor
func testManyObservationsWithLongConcurrentWrite() throws {
// We'll start many observations
let observationCount = 100
@@ -1157,6 +1159,7 @@ class ValueObservationTests: GRDBTestCase {
}
// Regression test for <https://github.com/groue/GRDB.swift/issues/1362>
@MainActor
func testIssue1362() throws {
func test(_ writer: some DatabaseWriter) throws {
try writer.write { try $0.execute(sql: "CREATE TABLE s(id INTEGER PRIMARY KEY AUTOINCREMENT)") }