@@ -124,7 +124,9 @@ public void shouldAwaitActiveExchange() throws InterruptedException {
124124
125125 // Complete the exchange one second into the future
126126 final Duration exchangeDuration = Duration .ofSeconds (1 );
127- final long startTime = System .nanoTime (); // taking custom start time just in case
127+ // taking start time before entering completeExchange to account for possible
128+ // delays in reaching server.stop().
129+ final long startTime = System .nanoTime ();
128130 completeExchange (exchangeDuration );
129131 log ("Complete Exchange triggered" );
130132
@@ -152,27 +154,26 @@ public void shouldAwaitActiveExchange() throws InterruptedException {
152154 * @throws InterruptedException if an unexpected interruption occurs
153155 */
154156 @ Test
155- public void shouldCompeteAfterDelay () throws InterruptedException {
157+ public void shouldCompleteAfterDelay () throws InterruptedException {
156158 // Initiate an exchange
157159 startExchange ();
158160 // Wait for the server to receive the exchange
159161 start .await ();
160162 log ("Exchange started" );
161163
162- // Complete the exchange 10 second into the future.
163- // Runs in parallel, so won't block the server stop
164- final Duration exchangeDuration = Duration .ofSeconds (Utils .adjustTimeout (10 ));
165- final long startTime = System .nanoTime (); // taking custom start time just in case
166- completeExchange (exchangeDuration );
167- log ("Complete Exchange triggered" );
168-
169-
170164 // Time the shutdown sequence
171165 final Duration delayDuration = Duration .ofSeconds (1 );
172166 log ("Shutdown triggered with the delay of " + delayDuration .getSeconds ());
173- final long elapsed = timeShutdown (delayDuration , startTime );
167+ final long elapsed = timeShutdown (delayDuration );
174168 log ("Shutdown complete" );
175169
170+ // Complete the exchange 10 second into the future.
171+ // Runs in parallel, so won't block the server stop
172+ final Duration exchangeDuration = Duration .ofSeconds (Utils .adjustTimeout (10 ));
173+ // taking start time before entering completeExchange to account for possible
174+ // delays in reaching server.stop().
175+ completeExchange (exchangeDuration );
176+ log ("Complete Exchange triggered" );
176177
177178 // The shutdown should not await the exchange to complete
178179 if (elapsed >= exchangeDuration .toNanos ()) {
0 commit comments