Akka FSM测试套件不';无法正确捕捉*起始状态*

Akka FSM测试套件不';无法正确捕捉*起始状态*,akka,akka-testkit,akka-fsm,Akka,Akka Testkit,Akka Fsm,我正在使用Akka FSM模拟移动的电梯(你要去:不要再去了!:-),并尝试使用常规测试工具包功能测试FSM,但我的理解或FSM的发布行为(或两者)似乎存在差距 以下是代码的相关部分: class LiftCarriageWithMovingState (val movingStateSimulator: ActorRef) extends Actor with LoggingFSM[LiftState,LiftData] with ActorLogging { val mxTime

我正在使用Akka FSM模拟移动的电梯(你要去:不要再去了!:-),并尝试使用常规测试工具包功能测试FSM,但我的理解或FSM的发布行为(或两者)似乎存在差距

以下是代码的相关部分:

class LiftCarriageWithMovingState (val movingStateSimulator: ActorRef) extends Actor
  with LoggingFSM[LiftState,LiftData]
  with ActorLogging
{
  val mxTimeToWaitStopping = 250 milliseconds
  private var pendingPassengerRequests: Vector[NextStop] = Vector.empty
  private var currentFloorID = 0 // Always start at Ground Floor

  val timeToReachNextFloor = 1000 millis  // up  or down, same time taken

  private val dontCare: StateFunction = {
    // ..
  }

  private val powerYourselfOff: StateFunction = {
    case Event(InstructedToPowerOff,_) =>
      stay
  }

  private val powerYourselfOn: StateFunction = {
    case Event(InstructedToPowerOn,_)  =>
      goto (PoweredOn)
  }

  private val beReady: StateFunction = {
    case Event(BeReady,_)          =>
      settleDownAtGroundFloor
      goto (Ready)
  }

  // .. other StateFunctions here

  startWith(PoweredOff,InitialData)

  when (PoweredOff) (powerYourselfOn orElse
                     dontCare)

  when (PoweredOn)  (powerYourselfOff orElse
                     beReady orElse
                     dontCare
  // ...
人们期望FSM在创建CurrentState消息并调用startWith函数后立即响应该消息,但事实并非如此。此测试(再次部分代码)失败:

因此:

我的理解有差距吗?如果是的话,请教育我

我还看到,同样的问题——以更概括的形式提出——没有得到回答。这难道不是Akka FSM和Testkit语义上的一个缺口,值得解决吗-P

"A LiftCarriage" must {
    "be ready, when it settles down after being PoweredOn" in {

      val testCarriageFSM = TestFSMRef(new LiftCarriageWithMovingState(movingStateSimulator))

      expectMsgPF() {
        case CurrentState(_,PoweredOff) => true // Line 46, see the stacktrace below
      }
 A LiftCarriage
[info] - must be ready, when it settles down after being PoweredOn *** FAILED ***
[info]   java.lang.AssertionError: assertion failed: timeout (3 seconds) during expectMsg:
[info]   at scala.Predef$.assert(Predef.scala:170)
[info]   at akka.testkit.TestKitBase$class.expectMsgPF(TestKit.scala:356)
[info]   at akka.testkit.TestKit.expectMsgPF(TestKit.scala:718)
[info]   at withExplicitMovingState.LiftCarriageMovingStoppingCorrectlyTest$$anonfun$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(LiftCarriageMovingStoppingCorrectlyTest.scala:46)
[info]   at withExplicitMovingState.LiftCarriageMovingStoppingCorrectlyTest$$anonfun$1$$anonfun$apply$mcV$sp$1.apply(LiftCarriageMovingStoppingCorrectlyTest.scala:42)
[info]   at withExplicitMovingState.LiftCarriageMovingStoppingCorrectlyTest$$anonfun$1$$anonfun$apply$mcV$sp$1.apply(LiftCarriageMovingStoppingCorrectlyTest.scala:42)