Skip to content

Commit

Permalink
Test app robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
jbachorik committed Oct 8, 2022
1 parent 1a80c19 commit 58e6b3d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
10 changes: 7 additions & 3 deletions btrace-instr/src/test/java/org/openjdk/btrace/RuntimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,14 @@ public void test(
Process client = attach(pid, testScript, cmdArgs, checkLines, stdout, stderr);

System.out.println("Detached.");
pw.println("done");
pw.flush();
boolean exitted = false;
while (!exitted) {
pw.println("done");
pw.flush();
exitted = client.waitFor(1, TimeUnit.SECONDS);
}

ret.set(client.waitFor());
ret.set(client.exitValue());

outT.join();
errT.join();
Expand Down
23 changes: 13 additions & 10 deletions btrace-instr/src/test/java/resources/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ public void run() {
t.setDaemon(true);
t.start();

String resp = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)).readLine();
System.out.println("Received " + resp + " - " + "done".equals(resp));
if ("done".equals(resp)) {
System.out.flush();
System.out.println(System.currentTimeMillis() + ": Interrupting the worker thread");
t.interrupt();
System.out.println(System.currentTimeMillis() + ": Waiting for the worker thread to finish");
t.join();
System.out.println(System.currentTimeMillis() + ": Worker thread finished");
}
do {
String resp = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)).readLine();
System.out.println("Received " + resp + " - " + "done".contains(resp));
if ("done".contains(resp)) {
System.out.flush();
System.out.println(System.currentTimeMillis() + ": Interrupting the worker thread");
t.interrupt();
System.out.println(System.currentTimeMillis() + ": Waiting for the worker thread to finish");
t.join();
System.out.println(System.currentTimeMillis() + ": Worker thread finished");
break;
}
} while (true);
}

private static long getPID() {
Expand Down

0 comments on commit 58e6b3d

Please sign in to comment.