These are chat archives for petabridge/akka-bootcamp

18th
Aug 2015
Michael Dadashyan
@mebymyself
Aug 18 2015 01:28
Hi there,
I am trying to understand how to use TestKit and have couple of questions
  1. If some ParentActor creates an ChildActor how that should be tested?
  2. If some ParentActor creates ChildActorA and ChildActorB and sends messages "A" and "B" accordingly how to test each Child receives the correct message?
    I am using MsTest but will understand any other Testing framework as well.
Bartosz Sypytkowski
@Horusiath
Aug 18 2015 06:51
@mebymyself
  1. you can split the actors and test each of them independently using mocked actors
  2. sometime your could just verify behavior of the whole group od the actors
Patrick Kelly
@featuresnap
Aug 18 2015 09:32
@mebymyself I am assuming you're finding it difficult to get access to the child to verify what messages it received. That's what I struggled with, at least. You could give the parent a Props as a constructor argument, that it would use to create its child. Replace the Props at testing time with one that produces a TestProbe. Or, your parent actor could have a virtual CreateChild() method; for testing the parent you can create a test double that inherits from the parent, and its overridden CreateChild() method returns a TestProbe or TestActor. One other approach that I have tried but didn't enjoy as much is for your child to log a Debug event upon receiving a certain message, and then use EventFilter expectation to prove that such a debug message is logged (presumably by the child) when you send a message to the parent.
Michael Dadashyan
@mebymyself
Aug 18 2015 22:07
@Horusiath
You are absolutely right! I was having trouble to test the Parent. It do some message processing and then initiate appropriate worker based on message payload. Now my test just checks if the specific payload resulted in correct message being sent. The fact whether child received the message or not is not important. It is kind of testing the framework.
@featuresnap
I am not big fan of adding constructor parameters or virtual methods just for the sake of testing. The solution is to really test one thing at the time as @Horusiath suggested.
Bobby
@bobbychopra
Aug 18 2015 23:35
@Horusiath any F# idiomatic way to access the Stash? or would you need to create F# class derived from Untyped Actor and implement interface IWithUnboundedStash ?