@@ -111,31 +111,33 @@ public void testMaxQueueLatency() throws Exception {
111111 context ,
112112 new TaskTrackingConfig (randomBoolean (), true , DEFAULT_EXECUTION_TIME_EWMA_ALPHA_FOR_TEST )
113113 );
114- executor .setupMetrics (meterRegistry , threadPoolName );
115- executor .prestartAllCoreThreads ();
116- logger .info ("--> executor: {}" , executor );
117-
118- // Check that the max is zero initially and after a reset.
119- assertEquals ("The queue latency should be initialized zero" , 0 , executor .getMaxQueueLatencyMillisSinceLastPollAndReset ());
120- executor .execute (() -> {});
121- safeAwait (barrier ); // Wait for the task to start, which means implies has finished the queuing stage.
122- assertEquals ("Ran one task of 1ms, should be the max" , 1 , executor .getMaxQueueLatencyMillisSinceLastPollAndReset ());
123- assertEquals ("The max was just reset, should be zero" , 0 , executor .getMaxQueueLatencyMillisSinceLastPollAndReset ());
124-
125- // Check that the max is kept across multiple calls, where the last is not the max.
126- adjustableTimedRunnable .setQueuedTimeTakenNanos (5000000 );
127- executeTask (executor , 1 );
128- safeAwait (barrier ); // Wait for the task to start, which means implies has finished the queuing stage.
129- adjustableTimedRunnable .setQueuedTimeTakenNanos (1000000 );
130- executeTask (executor , 1 );
131- safeAwait (barrier );
132- assertEquals ("Max should not be the last task" , 5 , executor .getMaxQueueLatencyMillisSinceLastPollAndReset ());
133- assertEquals ("The max was just reset, should be zero" , 0 , executor .getMaxQueueLatencyMillisSinceLastPollAndReset ());
114+ try {
115+ executor .prestartAllCoreThreads ();
116+ logger .info ("--> executor: {}" , executor );
134117
135- // Clean up.
136- assertThat (executor .getOngoingTasks ().toString (), executor .getOngoingTasks ().size (), equalTo (0 ));
137- executor .shutdown ();
138- executor .awaitTermination (10 , TimeUnit .SECONDS );
118+ // Check that the max is zero initially and after a reset.
119+ assertEquals ("The queue latency should be initialized zero" , 0 , executor .getMaxQueueLatencyMillisSinceLastPollAndReset ());
120+ executor .execute (() -> {
121+ });
122+ safeAwait (barrier ); // Wait for the task to start, which means implies has finished the queuing stage.
123+ assertEquals ("Ran one task of 1ms, should be the max" , 1 , executor .getMaxQueueLatencyMillisSinceLastPollAndReset ());
124+ assertEquals ("The max was just reset, should be zero" , 0 , executor .getMaxQueueLatencyMillisSinceLastPollAndReset ());
125+
126+ // Check that the max is kept across multiple calls, where the last is not the max.
127+ adjustableTimedRunnable .setQueuedTimeTakenNanos (5000000 );
128+ executeTask (executor , 1 );
129+ safeAwait (barrier ); // Wait for the task to start, which means implies has finished the queuing stage.
130+ adjustableTimedRunnable .setQueuedTimeTakenNanos (1000000 );
131+ executeTask (executor , 1 );
132+ safeAwait (barrier );
133+ assertEquals ("Max should not be the last task" , 5 , executor .getMaxQueueLatencyMillisSinceLastPollAndReset ());
134+ assertEquals ("The max was just reset, should be zero" , 0 , executor .getMaxQueueLatencyMillisSinceLastPollAndReset ());
135+ } finally {
136+ // Clean up.
137+ assertThat (executor .getOngoingTasks ().toString (), executor .getOngoingTasks ().size (), equalTo (0 ));
138+ executor .shutdown ();
139+ executor .awaitTermination (10 , TimeUnit .SECONDS );
140+ }
139141 }
140142
141143 /** Use a runnable wrapper that simulates a task with unknown failures. */
0 commit comments