Skip to content

Commit ab3e451

Browse files
committed
Wrap resilience tests in detached task
Putting the main function under the MainActor appears to have accidentally "fixed" the resilience tests on Windows. I've put the entry to those tests under a separate task to try and avoid accidentally hiding the bug behind the main actor.
1 parent 41499d0 commit ab3e451

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

test/Concurrency/Runtime/class_resilience.swift

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,24 @@ func virtualWait<T>(orThrow: Bool, _ c: BaseClass<T>) async throws {
5555
return try await c.wait(orThrow: orThrow)
5656
}
5757

58-
59-
60-
6158
@main struct Main {
6259
static func main() async {
63-
var AsyncVTableMethodSuite = TestSuite("ResilientClass")
64-
AsyncVTableMethodSuite.test("AsyncVTableMethod") {
65-
let x = MyDerived(value: 321)
60+
let task = Task.detached {
61+
var AsyncVTableMethodSuite = TestSuite("ResilientClass")
62+
AsyncVTableMethodSuite.test("AsyncVTableMethod") {
63+
let x = MyDerived(value: 321)
6664

67-
await virtualWaitForNothing(x)
65+
await virtualWaitForNothing(x)
6866

69-
expectEqual(642, await virtualWait(x))
70-
expectEqual(246, await virtualWaitForInt(x))
67+
expectEqual(642, await virtualWait(x))
68+
expectEqual(246, await virtualWaitForInt(x))
7169

72-
expectNil(try? await virtualWait(orThrow: true, x))
73-
try! await virtualWait(orThrow: false, x)
70+
expectNil(try? await virtualWait(orThrow: true, x))
71+
try! await virtualWait(orThrow: false, x)
72+
}
73+
await runAllTestsAsync()
7474
}
75-
await runAllTestsAsync()
75+
76+
await task.value
7677
}
7778
}

test/Concurrency/Runtime/protocol_resilience.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,23 @@ func genericWait<T : Awaitable>(orThrow: Bool, _ t: T) async throws {
6262

6363
@main struct Main {
6464
static func main() async {
65-
var AsyncProtocolRequirementSuite = TestSuite("ResilientProtocol")
65+
let task = Task.detached {
66+
var AsyncProtocolRequirementSuite = TestSuite("ResilientProtocol")
6667

67-
AsyncProtocolRequirementSuite.test("AsyncProtocolRequirement") {
68-
let x = IntAwaitable()
68+
AsyncProtocolRequirementSuite.test("AsyncProtocolRequirement") {
69+
let x = IntAwaitable()
6970

70-
await genericWaitForNothing(x)
71+
await genericWaitForNothing(x)
7172

72-
expectEqual(123, await genericWait(x))
73-
expectEqual(321, await genericWaitForInt(x))
73+
expectEqual(123, await genericWait(x))
74+
expectEqual(321, await genericWaitForInt(x))
7475

75-
expectNil(try? await genericWait(orThrow: true, x))
76-
try! await genericWait(orThrow: false, x)
76+
expectNil(try? await genericWait(orThrow: true, x))
77+
try! await genericWait(orThrow: false, x)
78+
}
79+
await runAllTestsAsync()
7780
}
78-
await runAllTestsAsync()
81+
82+
await task.value
7983
}
8084
}

0 commit comments

Comments
 (0)