Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 43 additions & 43 deletions test/Distributed/Runtime/distributed_actor_init_local.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime

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

// Disabled temporarily until we figure out why the test is flaky.
// REQUIRES: rdar84586299

import _Distributed

enum MyError: Error {
Expand Down Expand Up @@ -76,6 +73,9 @@ struct ActorAddress: ActorIdentity {
}
}

// global to track available IDs
var nextID: Int = 1

@available(SwiftStdlib 5.5, *)
struct FakeTransport: ActorTransport {
func decodeIdentity(from decoder: Decoder) throws -> AnyActorIdentity {
Expand All @@ -89,7 +89,8 @@ struct FakeTransport: ActorTransport {

func assignIdentity<Act>(_ actorType: Act.Type) -> AnyActorIdentity
where Act: DistributedActor {
let id = ActorAddress(parse: "xxx")
let id = ActorAddress(parse: "\(nextID)")
nextID += 1
print("assign type:\(actorType), id:\(id)")
return .init(id)
}
Expand All @@ -109,48 +110,47 @@ struct FakeTransport: ActorTransport {
func test() async {
let transport = FakeTransport()

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

test.append(LocalWorker(transport: transport))
// CHECK: assign type:LocalWorker, id:ActorAddress(address: "[[ID1:.*]]")
// CHECK: ready actor:main.LocalWorker, id:AnyActorIdentity(ActorAddress(address: "[[ID1]]"))

_ = PickATransport1(kappa: transport, other: 0)
// CHECK: assign type:PickATransport1, id:ActorAddress(address: "[[ID:.*]]")
// CHECK: ready actor:main.PickATransport1, id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
// CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
test.append(PickATransport1(kappa: transport, other: 0))
// CHECK: assign type:PickATransport1, id:ActorAddress(address: "[[ID2:.*]]")
// CHECK: ready actor:main.PickATransport1, id:AnyActorIdentity(ActorAddress(address: "[[ID2]]"))

_ = try? Throwy(transport: transport, doThrow: false)
// CHECK: assign type:Throwy, id:ActorAddress(address: "[[ID:.*]]")
// CHECK: ready actor:main.Throwy, id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
// CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
test.append(try? Throwy(transport: transport, doThrow: false))
// CHECK: assign type:Throwy, id:ActorAddress(address: "[[ID3:.*]]")
// CHECK: ready actor:main.Throwy, id:AnyActorIdentity(ActorAddress(address: "[[ID3]]"))

_ = try? Throwy(transport: transport, doThrow: true)
// CHECK: assign type:Throwy, id:ActorAddress(address: "[[ID:.*]]")
test.append(try? Throwy(transport: transport, doThrow: true))
// CHECK: assign type:Throwy, id:ActorAddress(address: "[[ID4:.*]]")
// CHECK-NOT: ready
// CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))

_ = try? ThrowBeforeFullyInit(transport: transport, doThrow: true)
// CHECK: assign type:ThrowBeforeFullyInit, id:ActorAddress(address: "[[ID:.*]]")
// FIXME: The two checks below should work, but do not currently, so they're disabled (rdar://84533820).
// MISSING-CHECK-NOT: ready actor:main.ThrowBeforeFullyInit
// MISSING-CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))

_ = await PickATransport2(other: 1, theTransport: transport)
// CHECK: assign type:PickATransport2, id:ActorAddress(address: "[[ID:.*]]")
// CHECK: ready actor:main.PickATransport2, id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))

// FIXME: The checks for this initializer should NOT pass, but currently do. (rdar://84533820)
_ = await Bug_CallsReadyTwice(transport: transport, wantBug: true)
// CHECK: assign type:Bug_CallsReadyTwice, id:ActorAddress(address: "[[ID:.*]]")
// CHECK: ready actor:main.Bug_CallsReadyTwice, id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
// CHECK-NEXT: ready actor:main.Bug_CallsReadyTwice, id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))

// TODO: it's not obvious why the resigns happen later for the async ones.
// might need to find a way to force the deallocation at a specific point,
// or just use check-dag or something.

// CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))
// CHECK: resign id:AnyActorIdentity(ActorAddress(address: "[[ID]]"))

test.append(try? ThrowBeforeFullyInit(transport: transport, doThrow: true))
// CHECK: assign type:ThrowBeforeFullyInit, id:ActorAddress(address: "[[ID5:.*]]")
// CHECK-NOT: ready

test.append(await PickATransport2(other: 1, theTransport: transport))
// CHECK: assign type:PickATransport2, id:ActorAddress(address: "[[ID6:.*]]")
// CHECK: ready actor:main.PickATransport2, id:AnyActorIdentity(ActorAddress(address: "[[ID6]]"))

test.append(await Bug_CallsReadyTwice(transport: transport, wantBug: true))
// CHECK: assign type:Bug_CallsReadyTwice, id:ActorAddress(address: "[[ID7:.*]]")
// CHECK: ready actor:main.Bug_CallsReadyTwice, id:AnyActorIdentity(ActorAddress(address: "[[ID7]]"))
// CHECK-NEXT: ready actor:main.Bug_CallsReadyTwice, id:AnyActorIdentity(ActorAddress(address: "[[ID7]]"))

// CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID1]]"))
// CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID2]]"))
// CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID3]]"))
// MISSING-CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID4]]")) // FIXME: should eventually work (rdar://84533820).
// MISSING-CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID5]]")) // FIXME: should eventually work (rdar://84533820).
// CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID6]]"))
// CHECK-DAG: resign id:AnyActorIdentity(ActorAddress(address: "[[ID7]]"))
}

@available(SwiftStdlib 5.5, *)
Expand Down