Skip to content

Commit

Permalink
[Distributed] More tests for local actor init, with specific transpor…
Browse files Browse the repository at this point in the history
…t type (#39788)
  • Loading branch information
ktoso authored Oct 19, 2021
1 parent 338cc32 commit c8b4e8e
Showing 1 changed file with 50 additions and 8 deletions.
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
}

}

0 comments on commit c8b4e8e

Please sign in to comment.