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

test: don't fail test if scheduled task runs more often than expected #10746

Merged

Conversation

oleschoenburg
Copy link
Member

If the test thread was blocked for a while, for example due to garbage collection, verifying that the task ran exactly 5 times within 2 seconds would fail because it ran more often than that.

With this change we just verify that the task ran at least 5 times within 2 seconds.

closes #10745

If the test thread was blocked for a while, for example due to garbage
collection, verifying that the task ran exactly 5 times within 2 seconds
would fail because it ran more often than that.

With this change we just verify that the task ran at least 5 times
within 2 seconds.
@github-actions
Copy link
Contributor

Test Results

   939 files  ±  0     939 suites  ±0   1h 46m 23s ⏱️ +34s
7 620 tests +78  7 613 ✔️ +79  7 💤 ±0  0  - 1 
7 810 runs  +78  7 801 ✔️ +79  9 💤 ±0  0  - 1 

Results for commit f4273e2. ± Comparison against base commit 0d9dba6.

@@ -288,7 +288,7 @@ public void shouldScheduleOnFixedRate() {
scheduleService.runAtFixedRate(Duration.ofMillis(10), mockedTask);

// then
verify(mockedTask, TIMEOUT.times(5)).execute(any());
verify(mockedTask, TIMEOUT.atLeast(5)).execute(any());
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't look like this test is testing really what it wants. To make it deterministic, one way would be to use ControlledActorScheduler. Then we can write:

    scheduleService.runAtFixedRate(Duration.ofSeconds(10), mockedTask);
    actorScheduler.runUntilDone();

    // verify it ran at the first interval
    clock.addTime(Duration.ofSeconds(10));
    actorScheduler.runUntilDone();
    verify(mockedTask, times(1)).execute(any());
 
   // verify it was rescheduled for the next interval
    clock.addTime(Duration.ofSeconds(10));
    actorScheduler.runUntilDone();
    verify(mockedTask, times(2)).execute(any());

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I interpreted the test more as a "see if runAtFixedRate works at all" test and not so much as a test that verifies specific timings.

I think it makes sense to test that runAtFixedRate runs jobs at a rate that is close to the requested rate but that'd be a separate test IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Then this test is enough. I don't think another test is required. I assume time based scheduling is already tested for actor scheduler.

Copy link
Contributor

@deepthidevaki deepthidevaki left a comment

Choose a reason for hiding this comment

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

Thanks 🎉

@oleschoenburg
Copy link
Member Author

bors merge

@zeebe-bors-camunda
Copy link
Contributor

Build succeeded:

@backport-action
Copy link
Collaborator

Successfully created backport PR #10750 for stable/8.1.

zeebe-bors-camunda bot added a commit that referenced this pull request Oct 18, 2022
10750: [Backport stable/8.1] test: don't fail test if scheduled task runs more often than expected r=oleschoenburg a=backport-action

# Description
Backport of #10746 to `stable/8.1`.

relates to #10745

Co-authored-by: Ole Schönburg <ole.schoenburg@gmail.com>
@korthout korthout added the version:8.1.3 Marks an issue as being completely or in parts released in 8.1.3 label Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
version:8.1.3 Marks an issue as being completely or in parts released in 8.1.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ProcessingScheduleServiceTest.shouldScheduleOnFixedRate is flaky
4 participants