Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Roiocam committed Aug 19, 2024
1 parent d5efa8e commit 9984d9c
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
}
}

def throwIOExceptionThenIllegalArgumentException(behvFactory: ActorRef[Event] => Behavior[Command]): Unit = {
def throwIOExceptionThenIllegalArgumentException(behvFactory: ActorRef[Event] => Behavior[Command])(
secondSignal: ReceivedSignal = ReceivedSignal(PreRestart)): Unit = {
val probe = TestProbe[Event]("evt")

val ref = spawn(behvFactory(probe.ref))
Expand All @@ -432,57 +433,60 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""

LoggingTestKit.error[IllegalArgumentException].expect {
ref ! Throw(new IllegalArgumentException("cat"))
probe.expectMessage(ReceivedSignal(PreRestart))
probe.expectMessage(secondSignal)
}

// verify that it's still alive and not stopped, IllegalStateException would stop it
ref ! Ping(2)
probe.expectMessage(Pong(2))
secondSignal match {
case ReceivedSignal(PreRestart) =>
// verify that it's still alive and not stopped, IllegalStateException would stop it
ref ! Ping(2)
probe.expectMessage(Pong(2))
}
}

"support nesting exceptions with different strategies" in throwIOExceptionThenIllegalArgumentException { probeRef =>
supervise(
supervise(targetBehavior(probeRef))
.onFailure[RuntimeException](SupervisorStrategy.stop))
.onFailure[Exception](SupervisorStrategy.restart)
}
}(ReceivedSignal(PostStop))

"support flattening exceptions with different strategies" in throwIOExceptionThenIllegalArgumentException {
probeRef =>
supervise(targetBehavior(probeRef))
.onFailure[RuntimeException](SupervisorStrategy.stop)
.onFailure[Exception](SupervisorStrategy.restart)
}
}(ReceivedSignal(PostStop))

"support nesting exceptions with outer restart and inner backoff strategies" in throwIOExceptionThenIllegalArgumentException {
probeRef =>
supervise(
supervise(targetBehavior(probeRef))
.onFailure[IllegalArgumentException](SupervisorStrategy.restartWithBackoff(10.millis, 10.millis, 0.0)))
.onFailure[IOException](SupervisorStrategy.restart)
}
}()

"support flattening exceptions with outer restart and inner backoff strategies" in throwIOExceptionThenIllegalArgumentException {
probeRef =>
supervise(targetBehavior(probeRef))
.onFailure[IllegalArgumentException](SupervisorStrategy.restartWithBackoff(10.millis, 10.millis, 0.0))
.onFailure[IOException](SupervisorStrategy.restart)
}
}()

"support nesting exceptions with inner restart and outer backoff strategies" in throwIOExceptionThenIllegalArgumentException {
probeRef =>
supervise(
supervise(targetBehavior(probeRef))
.onFailure[IllegalArgumentException](SupervisorStrategy.restart))
.onFailure[IOException](SupervisorStrategy.restartWithBackoff(10.millis, 10.millis, 0.0))
}
}()

"support flattening exceptions with inner restart and outer backoff strategies" in throwIOExceptionThenIllegalArgumentException {
probeRef =>
supervise(targetBehavior(probeRef))
.onFailure[IllegalArgumentException](SupervisorStrategy.restart)
.onFailure[IOException](SupervisorStrategy.restartWithBackoff(10.millis, 10.millis, 0.0))
}
}()

"stop when not supervised" in {
val probe = TestProbe[Event]("evt")
Expand Down

0 comments on commit 9984d9c

Please sign in to comment.