Skip to content

Commit f8fb279

Browse files
committed
improve robustness of dist actor test
We were seeing flaky runs due to the hard-to-determine order and point at which the actor instances were being deallocated in the old version of the test. In addition, all of the actor addresses were the same, so moving the point of deallocation would give us a less rigorous test. This patch puts all of the instances in an array so that we can rely on CHECK-DAG to check for the deallocations in any order, as a group at the end of the test. The deallocations are now identifiable using a simple counter for the addresses. resolves rdar://84574311
1 parent 8b34fca commit f8fb279

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

test/Distributed/Runtime/distributed_actor_init_local.swift

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
// UNSUPPORTED: use_os_stdlib
99
// UNSUPPORTED: back_deployment_runtime
1010

11-
// FIXME(distributed): we need to revisit what's going on on windows with distributed actors rdar://84574311
11+
// FIXME(distributed): we need to revisit what's going on on windows with distributed actors rdar://83859906
1212
// UNSUPPORTED: OS=windows-msvc
1313

14-
// Disabled temporarily until we figure out why the test is flaky.
15-
// REQUIRES: rdar84586299
16-
1714
import _Distributed
1815

1916
enum MyError: Error {
@@ -76,6 +73,9 @@ struct ActorAddress: ActorIdentity {
7673
}
7774
}
7875

76+
// global to track available IDs
77+
var nextID: Int = 1
78+
7979
@available(SwiftStdlib 5.5, *)
8080
struct FakeTransport: ActorTransport {
8181
func decodeIdentity(from decoder: Decoder) throws -> AnyActorIdentity {
@@ -89,7 +89,8 @@ struct FakeTransport: ActorTransport {
8989

9090
func assignIdentity<Act>(_ actorType: Act.Type) -> AnyActorIdentity
9191
where Act: DistributedActor {
92-
let id = ActorAddress(parse: "xxx")
92+
let id = ActorAddress(parse: "\(nextID)")
93+
nextID += 1
9394
print("assign type:\(actorType), id:\(id)")
9495
return .init(id)
9596
}
@@ -109,48 +110,47 @@ struct FakeTransport: ActorTransport {
109110
func test() async {
110111
let transport = FakeTransport()
111112

112-
_ = LocalWorker(transport: transport)
113-
// CHECK: assign type:LocalWorker, id:ActorAddress(address: "[[ID:.*]]")
114-
// CHECK: ready actor:main.LocalWorker, id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
115-
// CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
113+
// NOTE: All allocated distributed actors should be saved in this array, so
114+
// that they will be deallocated together at the end of this test!
115+
// This convention helps ensure that the test is not flaky.
116+
var test: [DistributedActor?] = []
117+
118+
test.append(LocalWorker(transport: transport))
119+
// CHECK: assign type:LocalWorker, id:ActorAddress(address: "[[ID1:.*]]")
120+
// CHECK: ready actor:main.LocalWorker, id:AnyActorIdentity(ActorAddress(address: "[[ID1]]"))
116121

117-
_ = PickATransport1(kappa: transport, other: 0)
118-
// CHECK: assign type:PickATransport1, id:ActorAddress(address: "[[ID:.*]]")
119-
// CHECK: ready actor:main.PickATransport1, id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
120-
// CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
122+
test.append(PickATransport1(kappa: transport, other: 0))
123+
// CHECK: assign type:PickATransport1, id:ActorAddress(address: "[[ID2:.*]]")
124+
// CHECK: ready actor:main.PickATransport1, id:AnyActorIdentity(ActorAddress(address: "[[ID2]]"))
121125

122-
_ = try? Throwy(transport: transport, doThrow: false)
123-
// CHECK: assign type:Throwy, id:ActorAddress(address: "[[ID:.*]]")
124-
// CHECK: ready actor:main.Throwy, id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
125-
// CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
126+
test.append(try? Throwy(transport: transport, doThrow: false))
127+
// CHECK: assign type:Throwy, id:ActorAddress(address: "[[ID3:.*]]")
128+
// CHECK: ready actor:main.Throwy, id:AnyActorIdentity(ActorAddress(address: "[[ID3]]"))
126129

127-
_ = try? Throwy(transport: transport, doThrow: true)
128-
// CHECK: assign type:Throwy, id:ActorAddress(address: "[[ID:.*]]")
130+
test.append(try? Throwy(transport: transport, doThrow: true))
131+
// CHECK: assign type:Throwy, id:ActorAddress(address: "[[ID4:.*]]")
129132
// CHECK-NOT: ready
130-
// CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
131-
132-
_ = try? ThrowBeforeFullyInit(transport: transport, doThrow: true)
133-
// CHECK: assign type:ThrowBeforeFullyInit, id:ActorAddress(address: "[[ID:.*]]")
134-
// FIXME: The two checks below should work, but do not currently, so they're disabled (rdar://84533820).
135-
// MISSING-CHECK-NOT: ready actor:main.ThrowBeforeFullyInit
136-
// MISSING-CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
137-
138-
_ = await PickATransport2(other: 1, theTransport: transport)
139-
// CHECK: assign type:PickATransport2, id:ActorAddress(address: "[[ID:.*]]")
140-
// CHECK: ready actor:main.PickATransport2, id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
141-
142-
// FIXME: The checks for this initializer should NOT pass, but currently do. (rdar://84533820)
143-
_ = await Bug_CallsReadyTwice(transport: transport, wantBug: true)
144-
// CHECK: assign type:Bug_CallsReadyTwice, id:ActorAddress(address: "[[ID:.*]]")
145-
// CHECK: ready actor:main.Bug_CallsReadyTwice, id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
146-
// CHECK-NEXT: ready actor:main.Bug_CallsReadyTwice, id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
147-
148-
// TODO: it's not obvious why the resigns happen later for the async ones.
149-
// might need to find a way to force the deallocation at a specific point,
150-
// or just use check-dag or something.
151-
152-
// CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
153-
// CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
133+
134+
test.append(try? ThrowBeforeFullyInit(transport: transport, doThrow: true))
135+
// CHECK: assign type:ThrowBeforeFullyInit, id:ActorAddress(address: "[[ID5:.*]]")
136+
// CHECK-NOT: ready
137+
138+
test.append(await PickATransport2(other: 1, theTransport: transport))
139+
// CHECK: assign type:PickATransport2, id:ActorAddress(address: "[[ID6:.*]]")
140+
// CHECK: ready actor:main.PickATransport2, id:AnyActorIdentity(ActorAddress(address: "[[ID6]]"))
141+
142+
test.append(await Bug_CallsReadyTwice(transport: transport, wantBug: true))
143+
// CHECK: assign type:Bug_CallsReadyTwice, id:ActorAddress(address: "[[ID7:.*]]")
144+
// CHECK: ready actor:main.Bug_CallsReadyTwice, id:AnyActorIdentity(ActorAddress(address: "[[ID7]]"))
145+
// CHECK-NEXT: ready actor:main.Bug_CallsReadyTwice, id:AnyActorIdentity(ActorAddress(address: "[[ID7]]"))
146+
147+
// CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID1]]"))
148+
// CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID2]]"))
149+
// CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID3]]"))
150+
// MISSING-CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID4]]")) // FIXME: should eventually work (rdar://84533820).
151+
// MISSING-CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID5]]")) // FIXME: should eventually work (rdar://84533820).
152+
// CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID6]]"))
153+
// CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID7]]"))
154154
}
155155

156156
@available(SwiftStdlib 5.5, *)

0 commit comments

Comments
 (0)