Skip to content
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

Merged

Conversation

bszwej
Copy link
Contributor

@bszwej bszwej commented Feb 14, 2020

Fixes #28604

This also needs to be backported to 2.5.x (PR for 2.5.x: #28618)

@lightbend-cla-validator

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:

http://www.lightbend.com/contribute/cla

@akka-ci
Copy link

akka-ci commented Feb 14, 2020

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!

@akka-ci akka-ci added the validating PR is currently being validated by Jenkins label Feb 14, 2020
counter.get() shouldBe 1

val cancellationResult = task.cancel()
cancellationResult shouldBe true
Copy link
Contributor Author

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), ()))
Copy link
Contributor Author

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).

@akka-ci akka-ci added needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed validating PR is currently being validated by Jenkins labels Feb 14, 2020
@akka-ci
Copy link

akka-ci commented Feb 14, 2020

Test FAILed.

1 similar comment
@akka-ci
Copy link

akka-ci commented Feb 14, 2020

Test FAILed.

Copy link
Member

@raboof raboof left a 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!

@raboof
Copy link
Member

raboof commented Feb 14, 2020

ah, it seems this needs a sbt akka-testkit/scalafmt

@akka-ci akka-ci added validating PR is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels Feb 14, 2020
@akka-ci
Copy link

akka-ci commented Feb 14, 2020

Test FAILed.

@bszwej
Copy link
Contributor Author

bszwej commented Feb 14, 2020

Thank you for the review @raboof 👍
I introduced the changes. validatePullRequest now passes.

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?

@raboof
Copy link
Member

raboof commented Feb 14, 2020

PLS BUILD

@raboof
Copy link
Member

raboof commented Feb 14, 2020

Should me, or you, create a PR for the backport?

Would be great if you can help out with that as well! Otherwise we'll take care of it (probably somewhere next week).

@akka-ci akka-ci added validating PR is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels Feb 14, 2020
@akka-ci
Copy link

akka-ci commented Feb 14, 2020

Test FAILed.

@bszwej
Copy link
Contributor Author

bszwej commented Feb 17, 2020

Would be great if you can help out with that as well! Otherwise we'll take care of it (probably somewhere next week).

I prepared a PR for 2.5.x: #28618

@akka-ci
Copy link

akka-ci commented Feb 17, 2020

Test FAILed.

@bszwej
Copy link
Contributor Author

bszwej commented Feb 18, 2020

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:

    "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
    }

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.

@raboof raboof self-requested a review February 18, 2020 08:50
@akka-ci akka-ci added validating PR is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels Feb 18, 2020
@akka-ci
Copy link

akka-ci commented Feb 18, 2020

Test FAILed.

@akka-ci akka-ci added validating PR is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels Feb 18, 2020
@akka-ci
Copy link

akka-ci commented Feb 18, 2020

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)
Copy link
Contributor Author

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
    }

@bszwej
Copy link
Contributor Author

bszwej commented Feb 19, 2020

@raboof I introduced the final changes in this PR, and also in the backport (#28618). Feel free to look again and/or merge.

@bszwej bszwej requested review from raboof and removed request for raboof February 24, 2020 06:13
Copy link
Member

@raboof raboof left a 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?

@akka-ci akka-ci added validating PR is currently being validated by Jenkins and removed tested PR that was successfully built and tested by Jenkins labels Feb 26, 2020
Copy link
Member

@raboof raboof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM!

@akka-ci akka-ci added tested PR that was successfully built and tested by Jenkins and removed validating PR is currently being validated by Jenkins labels Feb 26, 2020
@akka-ci
Copy link

akka-ci commented Feb 26, 2020

Test PASSed.

@johanandren johanandren merged commit 717d72f into akka:master Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tested PR that was successfully built and tested by Jenkins to-be-backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ExplicitlyTriggeredScheduler does not cancel tasks in Akka Testkit
5 participants