Skip to content

Commit ffeaba4

Browse files
committed
Tests: Make distributed_actor_custom_executor_availability.swift use an explicit deployment target.
Split distributed_actor_custom_executor_availability.swift into two tests, one that only runs on existing platforms that support back deployment to Swift 5.7 aligned runtimes, and another test that is not restricted by platform that tests behavior when deploying to a Swift 5.9 aligned runtime or later.
1 parent 35be876 commit ffeaba4

File tree

3 files changed

+110
-78
lines changed

3 files changed

+110
-78
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import Distributed
2+
import FakeDistributedActorSystems
3+
4+
@available(SwiftStdlib 5.7, *)
5+
typealias DefaultDistributedActorSystem = LocalTestingDistributedActorSystem
6+
7+
@available(SwiftStdlib 5.7, *)
8+
distributed actor FiveSevenActor_NothingExecutor {
9+
nonisolated var unownedExecutor: UnownedSerialExecutor {
10+
print("get unowned executor")
11+
return MainActor.sharedUnownedExecutor
12+
}
13+
14+
distributed func test(x: Int) async throws {
15+
print("executed: \(#function)")
16+
defer {
17+
print("done executed: \(#function)")
18+
}
19+
MainActor.assumeIsolated {
20+
// ignore
21+
}
22+
}
23+
}
24+
25+
@available(SwiftStdlib 5.9, *)
26+
distributed actor FiveNineActor_NothingExecutor {
27+
nonisolated var unownedExecutor: UnownedSerialExecutor {
28+
print("get unowned executor")
29+
return MainActor.sharedUnownedExecutor
30+
}
31+
32+
distributed func test(x: Int) async throws {
33+
print("executed: \(#function)")
34+
defer {
35+
print("done executed: \(#function)")
36+
}
37+
MainActor.assumeIsolated {
38+
// ignore
39+
}
40+
}
41+
}
42+
43+
@available(SwiftStdlib 5.7, *)
44+
distributed actor FiveSevenActor_FiveNineExecutor {
45+
@available(SwiftStdlib 5.9, *)
46+
nonisolated var unownedExecutor: UnownedSerialExecutor {
47+
print("get unowned executor")
48+
return MainActor.sharedUnownedExecutor
49+
}
50+
51+
distributed func test(x: Int) async throws {
52+
print("executed: \(#function)")
53+
defer {
54+
print("done executed: \(#function)")
55+
}
56+
MainActor.assumeIsolated {
57+
// ignore
58+
}
59+
}
60+
}

test/Distributed/Runtime/distributed_actor_custom_executor_availability.swift

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift
3-
// RUN: %target-build-swift -Xfrontend -disable-availability-checking -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
3+
// RUN: %target-build-swift -parse-as-library -target %target-swift-abi-5.7-triple -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift %S/../Inputs/CustomSerialExecutorAvailability.swift -o %t/a.out
44
// RUN: %target-codesign %t/a.out
5-
// RUN: %target-run %t/a.out
5+
// RUN: %target-run %t/a.out
6+
7+
// These are the only platforms for which compiling a Swift 5.7 aligned deployment target is possible.
8+
// REQUIRES: OS=macosx || OS=ios || OS=watchos || OS=tvos
69

710
// REQUIRES: executable_test
811
// REQUIRES: concurrency
@@ -16,65 +19,6 @@
1619

1720
import StdlibUnittest
1821
import Distributed
19-
import FakeDistributedActorSystems
20-
21-
@available(SwiftStdlib 5.7, *)
22-
typealias DefaultDistributedActorSystem = LocalTestingDistributedActorSystem
23-
24-
@available(SwiftStdlib 5.7, *)
25-
distributed actor FiveSevenActor_NothingExecutor {
26-
nonisolated var unownedExecutor: UnownedSerialExecutor {
27-
print("get unowned executor")
28-
return MainActor.sharedUnownedExecutor
29-
}
30-
31-
distributed func test(x: Int) async throws {
32-
print("executed: \(#function)")
33-
defer {
34-
print("done executed: \(#function)")
35-
}
36-
MainActor.assumeIsolated {
37-
// ignore
38-
}
39-
}
40-
}
41-
42-
@available(SwiftStdlib 5.9, *)
43-
distributed actor FiveNineActor_NothingExecutor {
44-
nonisolated var unownedExecutor: UnownedSerialExecutor {
45-
print("get unowned executor")
46-
return MainActor.sharedUnownedExecutor
47-
}
48-
49-
distributed func test(x: Int) async throws {
50-
print("executed: \(#function)")
51-
defer {
52-
print("done executed: \(#function)")
53-
}
54-
MainActor.assumeIsolated {
55-
// ignore
56-
}
57-
}
58-
}
59-
60-
@available(SwiftStdlib 5.7, *)
61-
distributed actor FiveSevenActor_FiveNineExecutor {
62-
@available(SwiftStdlib 5.9, *)
63-
nonisolated var unownedExecutor: UnownedSerialExecutor {
64-
print("get unowned executor")
65-
return MainActor.sharedUnownedExecutor
66-
}
67-
68-
distributed func test(x: Int) async throws {
69-
print("executed: \(#function)")
70-
defer {
71-
print("done executed: \(#function)")
72-
}
73-
MainActor.assumeIsolated {
74-
// ignore
75-
}
76-
}
77-
}
7822

7923
@main struct Main {
8024
static func main() async {
@@ -83,7 +27,6 @@ distributed actor FiveSevenActor_FiveNineExecutor {
8327

8428
let system = LocalTestingDistributedActorSystem()
8529

86-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
8730
tests.test("5.7 actor, no availability executor property => no custom executor") {
8831
expectCrashLater(withMessage: "Fatal error: Incorrect actor executor assumption; Expected 'MainActor' executor.")
8932
try! await FiveSevenActor_NothingExecutor(actorSystem: system).test(x: 42)
@@ -97,22 +40,6 @@ distributed actor FiveSevenActor_FiveNineExecutor {
9740
expectCrashLater(withMessage: "Fatal error: Incorrect actor executor assumption; Expected 'MainActor' executor.")
9841
try! await FiveSevenActor_FiveNineExecutor(actorSystem: system).test(x: 42)
9942
}
100-
#else
101-
// On non-apple platforms the SDK comes with the toolchains,
102-
// so the feature works because we're executing in a 5.9 context already,
103-
// which otherwise could not have been compiled
104-
tests.test("non apple platform: 5.7 actor, no availability executor property => no custom executor") {
105-
try! await FiveSevenActor_NothingExecutor(actorSystem: system).test(x: 42)
106-
}
107-
108-
tests.test("non apple platform: 5.9 actor, no availability executor property => custom executor") {
109-
try! await FiveNineActor_NothingExecutor(actorSystem: system).test(x: 42)
110-
}
111-
112-
tests.test("non apple platform: 5.7 actor, 5.9 executor property => no custom executor") {
113-
try! await FiveSevenActor_FiveNineExecutor(actorSystem: system).test(x: 42)
114-
}
115-
#endif
11643

11744
await runAllTestsAsync()
11845
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift
3+
// RUN: %target-build-swift -parse-as-library -target %target-swift-abi-5.9-triple -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift %S/../Inputs/CustomSerialExecutorAvailability.swift -o %t/a.out
4+
// RUN: %target-codesign %t/a.out
5+
// RUN: %target-run %t/a.out
6+
7+
// REQUIRES: executable_test
8+
// REQUIRES: concurrency
9+
// REQUIRES: distributed
10+
// REQUIRES: concurrency_runtime
11+
// UNSUPPORTED: back_deployment_runtime
12+
13+
// UNSUPPORTED: back_deploy_concurrency
14+
// UNSUPPORTED: use_os_stdlib
15+
// UNSUPPORTED: freestanding
16+
17+
import StdlibUnittest
18+
import Distributed
19+
20+
@main struct Main {
21+
static func main() async {
22+
if #available(SwiftStdlib 5.9, *) {
23+
let tests = TestSuite("DistributedActorExecutorAvailabilitySwift59")
24+
25+
let system = LocalTestingDistributedActorSystem()
26+
27+
// On non-apple platforms the SDK comes with the toolchains,
28+
// so the feature works because we're executing in a 5.9 context already,
29+
// which otherwise could not have been compiled
30+
tests.test("non apple platform: 5.7 actor, no availability executor property => no custom executor") {
31+
try! await FiveSevenActor_NothingExecutor(actorSystem: system).test(x: 42)
32+
}
33+
34+
tests.test("non apple platform: 5.9 actor, no availability executor property => custom executor") {
35+
try! await FiveNineActor_NothingExecutor(actorSystem: system).test(x: 42)
36+
}
37+
38+
tests.test("non apple platform: 5.7 actor, 5.9 executor property => no custom executor") {
39+
try! await FiveSevenActor_FiveNineExecutor(actorSystem: system).test(x: 42)
40+
}
41+
42+
await runAllTestsAsync()
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)