Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ingted/4a5d14ff49a87c97c1f9d786feb308ba to your computer and use it in GitHub Desktop.
Save ingted/4a5d14ff49a87c97c1f9d786feb308ba to your computer and use it in GitHub Desktop.
// wrapper function over TestKit.ActorOfAsTestActorRef
let spawnAsTestRef (tck:Tck) (props: Props<'T>) : IActorRef<'T> =
typed (tck.ActorOfAsTestActorRef<FunActor<'T>>(props.ToProps(), tck.TestActor) :> IActorRef)
[<Fact>]
let ``Parent should create child`` () = testDefault <| fun tck ->
// child actor definition
let child (ctx: Actor<_>) msg = ctx.Sender() <! "hello" |> ignored
// parent actor defintion
let rec parent (ctx: Actor<_>) =
// spawn child
let childRef = spawnAnonymous ctx (props (actorOf2 child))
let rec loop () = actor {
let! msg = ctx.Receive()
childRef <<! msg // forward message to child
return loop()
}
loop ()
let testedParent = spawnAsTestRef tck (props parent)
testedParent <! "this should be forwarded to the child"
expectMsg tck "hello" |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment