4242import java .util .List ;
4343import java .util .Map ;
4444
45- import static org .junit .jupiter .api .Assertions .assertEquals ;
46- import static org .junit .jupiter .api .Assertions .assertFalse ;
47- import static org .junit .jupiter .api .Assertions .assertNotEquals ;
48- import static org .junit .jupiter .api .Assertions .assertNotNull ;
49- import static org .junit .jupiter .api .Assertions .assertNull ;
50- import static org .junit .jupiter .api .Assertions .assertSame ;
51- import static org .junit .jupiter .api .Assertions .assertTrue ;
52- import static org .junit .jupiter .api .Assertions .fail ;
45+ import static org .junit .jupiter .api .Assertions .*;
5346
5447/** Tests creation of {@link Service}s and execution of {@link Task}s. */
5548public class ServiceTest extends TestBase {
@@ -204,8 +197,12 @@ public void testCrashWithActiveTask() throws InterruptedException, IOException {
204197 "print('six')\n " +
205198 "sys.stdout.flush()\n " +
206199 "sys.stderr.write('seven\\ n')\n " +
200+ "task.update(\" crash-me\" )\n " +
207201 "import time; time.sleep(999)\n " ;
208- Task task = service .task (script );
202+ boolean [] ready = {false };
203+ Task task = service .task (script ).listen (e -> {
204+ if ("crash-me" .equals (e .message )) ready [0 ] = true ;
205+ });
209206
210207 // Record any crash reported in the task notifications.
211208 String [] reportedError = {null };
@@ -216,8 +213,9 @@ public void testCrashWithActiveTask() throws InterruptedException, IOException {
216213 });
217214 // Launch the task.
218215 task .start ();
219- // Simulate a crash after 500ms has gone by.
220- Thread .sleep (500 );
216+
217+ // Simulate a crash after the script has emitted its output.
218+ while (!ready [0 ]) Thread .sleep (5 );
221219 service .kill ();
222220
223221 // Wait for the service to fully shut down after the crash.
0 commit comments