-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ExplicitlyTriggeredScheduler cancellation #28614
Fix ExplicitlyTriggeredScheduler cancellation #28614
Conversation
…redScheduler cancellation bug.
Hi @bszwej, Thank you for your contribution! We really value the time you've taken to put this together. Before we proceed with reviewing this pull request, please sign the Lightbend Contributors License Agreement: |
Thank you for your pull request! After a quick sanity check one of the team will reply with 'OK TO TEST' to kick off our automated validation on Jenkins. This compiles the project, runs the tests, and checks for things like binary compatibility and source code formatting. When two team members have also manually reviewed and (perhaps after asking for some amendments) accepted your contribution, it should be good to be merged. For more details about our contributing process, check out CONTRIBUTING.md - and feel free to ask! |
counter.get() shouldBe 1 | ||
|
||
val cancellationResult = task.cancel() | ||
cancellationResult shouldBe true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before applying the fix, this test was failing.
val runResult = Try(task.runnable.run()) | ||
scheduled.remove(task) | ||
|
||
if (runResult.isSuccess) | ||
task.interval.foreach(i => scheduled.put(task.copy(time = task.time + i.toMillis), ())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before we were updating the task with new execution time. Because of this, the Cancellable was left with stale reference (this line: https://github.com/akka/akka/pull/28614/files#diff-7a1a738a6673f4092734cfa193957d7dR109), and hence the task could not be canceled (=removed from the scheduled map).
Test FAILed. |
1 similar comment
Test FAILed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, one nitpick about the class name of the test but otherwise LGTM!
akka-testkit/src/test/scala/akka/testkit/TestExplicitlyTriggeredScheduler.scala
Outdated
Show resolved
Hide resolved
ah, it seems this needs a |
Test FAILed. |
Thank you for the review @raboof 👍 On Jenkins it failed for some other reason. How can we rerun it? Also, can we backport it to 2.5.x according to: https://github.com/akka/akka/blob/master/CONTRIBUTING.md#backporting? Should me, or you, create a PR for the backport? |
PLS BUILD |
Would be great if you can help out with that as well! Otherwise we'll take care of it (probably somewhere next week). |
Test FAILed. |
I prepared a PR for 2.5.x: #28618 |
Test FAILed. |
I just found one more problem with the new implementation. Since we're storing Items as keys in the map (Item(interval: Option[FiniteDuration], runnable: Runnable)), the following test would not pass:
since it'd try to insert 2 duplicated entries into the map. Let's refrain from merging this PR now. I'll come with a better solution in the following days. |
Test FAILed. |
Test PASSed. |
@@ -94,9 +101,9 @@ class ExplicitlyTriggeredScheduler(@unused config: Config, log: LoggingAdapter, | |||
interval: Option[FiniteDuration], | |||
runnable: Runnable): Cancellable = { | |||
val firstTime = currentTime.get + initialDelay.toMillis | |||
val item = Item(firstTime, interval, runnable) | |||
val item = Item(UUID.randomUUID(), interval, runnable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added uniqueness to Item
, because otherwise, the following test would fail:
"schedule many tasks executed once" in new TestScope {
scheduler.scheduleOnce(1.seconds, runnable)(system.dispatcher)
scheduler.scheduleOnce(1.seconds, runnable)(system.dispatcher)
scheduler.timePasses(2.seconds)
counter.get() shouldBe 2 // fails, because counter.get() is 1
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking very good - perhaps we could avoid needing the UUID by making Item
a non-case class?
...ilters/2.6.3.backwards.excludes/28604-fix-ExplicitlyTriggeredScheduler-cancellation.excludes
Outdated
Show resolved
Hide resolved
akka-testkit/src/main/scala/akka/testkit/ExplicitlyTriggeredScheduler.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! LGTM!
Test PASSed. |
Fixes #28604
This also needs to be backported to 2.5.x (PR for 2.5.x: #28618)