Skip to content

[Distributed] More tests for local actor init, with specific transport type #39788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
58 changes: 50 additions & 8 deletions test/Distributed/distributed_actor_initialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,27 @@

import _Distributed

@available(SwiftStdlib 5.5, *)
distributed actor OK0 { }

@available(SwiftStdlib 5.5, *)
distributed actor OK1 {
var x: Int = 1
// ok, since all fields are initialized, the constructor can be synthesized
}

// TODO(distributed): test all the FIXITs in this file

@available(SwiftStdlib 5.5, *)
distributed actor Bad1 {
init() {
// expected-error@-1 {{designated distributed actor initializer 'init()' is missing required ActorTransport parameter}}
}
}

@available(SwiftStdlib 5.5, *)
distributed actor Bad12 {
init(x: String) {
// expected-error@-1 {{designated distributed actor initializer 'init(x:)' is missing required ActorTransport parameter}}
}
}

@available(SwiftStdlib 5.5, *)
distributed actor OK2 {
var x: Int

Expand All @@ -38,7 +33,6 @@ distributed actor OK2 {
}
}

@available(SwiftStdlib 5.5, *)
distributed actor Bad2 {
var x: Int = 1

Expand All @@ -47,7 +41,6 @@ distributed actor Bad2 {
}
}

@available(SwiftStdlib 5.5, *)
distributed actor OK3 {
var x: Int

Expand All @@ -56,11 +49,60 @@ distributed actor OK3 {
}
}

@available(SwiftStdlib 5.5, *)
distributed actor OKMulti {

convenience init(y: Int, transport: ActorTransport) { // ok
self.init(transport: transport)
}

}

distributed actor OKMultiDefaultValues {

convenience init(y: Int, transport: ActorTransport, x: Int = 1234) { // ok
self.init(transport: transport)
}

}

// ==== ------------------------------------------------------------------------
// MARK: Specific transport

struct ActorAddress: ActorIdentity {
let address: String
init(parse address : String) {
self.address = address
}
}

struct FakeTransport: ActorTransport {
func decodeIdentity(from decoder: Decoder) throws -> AnyActorIdentity {
fatalError("not implemented \(#function)")
}

func resolve<Act>(_ identity: AnyActorIdentity, as actorType: Act.Type) throws -> Act?
where Act: DistributedActor {
return nil
}

func assignIdentity<Act>(_ actorType: Act.Type) -> AnyActorIdentity
where Act: DistributedActor {
.init(ActorAddress(parse: ""))
}

public func actorReady<Act>(_ actor: Act)
where Act: DistributedActor {
print("\(#function):\(actor)")
}

func resignIdentity(_ id: AnyActorIdentity) {}
}

distributed actor OKSpecificTransportType {

init(y: Int, transport fake: FakeTransport) { // ok
defer { fake.actorReady(self) }
// nothing
}

}