Skip to content

Commit

Permalink
Fix flaky scheduling instrumentation test
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed May 18, 2017
1 parent e0cc0ae commit 7e65bbe
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ class MetricsSchedulingAspectTest {
@Autowired
MeterRegistry registry;

@Autowired
ThreadPoolTaskScheduler scheduler;

@Test
void scheduledIsInstrumented() {
void scheduledIsInstrumented() throws InterruptedException {
assertThat(registry.findMeter(Timer.class, "beeper"))
.hasValueSatisfying(t -> assertThat(t.count()).isEqualTo(1));

Expand All @@ -57,6 +60,8 @@ void scheduledIsInstrumented() {
// make sure longBeep continues running until we have a chance to observe it in the active state
observeLongTaskLatch.countDown();

while(scheduler.getActiveCount() > 0) {}

// now the long beeper has contributed to the beep count as well
assertThat(registry.findMeter(Timer.class, "beeper"))
.hasValueSatisfying(t -> assertThat(t.count()).isEqualTo(2));
Expand All @@ -72,7 +77,7 @@ MeterRegistry registry() {
}

@Bean
TaskScheduler scheduler() {
ThreadPoolTaskScheduler scheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
// this way, executing longBeep doesn't block the short tasks from running
scheduler.setPoolSize(5);
Expand Down

0 comments on commit 7e65bbe

Please sign in to comment.