Skip to content

Commit eba0eb2

Browse files
committed
Make crash test more reliably timed
Instead of waiting a fixed 500s, we now wait till the task is ready to be crashed -- i.e. when it is done emitting all of its output.
1 parent 4aa1a3f commit eba0eb2

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/test/java/org/apposed/appose/ServiceTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,7 @@
4242
import java.util.List;
4343
import 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. */
5548
public 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

Comments
 (0)