Skip to content

Commit

Permalink
jdi tests: more logging, reduce timeout
Browse files Browse the repository at this point in the history
jdi tests do not start on I Builds and we don't know why.
  • Loading branch information
EcljpseB0T authored and jukzi committed Sep 11, 2024
1 parent 616a818 commit 8c1b934
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,9 @@ private void injectVMArgs(Vector<String> commandLine) {
private Process exec(Vector<String> commandLine) throws IOException {
String[] vmString = new String[commandLine.size()];
commandLine.toArray(vmString);
return Runtime.getRuntime().exec(vmString);
Process exec = Runtime.getRuntime().exec(vmString);
System.out.println("launched with pid=" + exec.pid() + ": " + String.join(" ", vmString));
return exec;
}


Expand All @@ -874,8 +876,9 @@ protected void connectToVM() {
startConsoleReaders();


// Contact the VM (try 10 times)
for (int i = 0; i < 10; i++) {
// Contact the VM (try at least 10 times for 5 seconds)
long n0 = System.nanoTime();
for (int i = 0; i < 10000; i++) {
try {
VirtualMachineManager manager = Bootstrap.virtualMachineManager();
List<AttachingConnector> connectors = manager.attachingConnectors();
Expand All @@ -893,15 +896,17 @@ protected void connectToVM() {
}
break;
} catch (IllegalConnectorArgumentsException e) {
e.printStackTrace();
} catch (IOException e) {
// System.out.println("Got exception: " + e.getMessage());
long n1 = System.nanoTime();
if (i > 10 && n1 - n0 > 5_000_000_000L) {
e.printStackTrace();
System.out.println("Could not contact the VM at localhost" + ":" + fBackEndPort + " after " + (n1 - n0) / 1_000_000 + "ms");
break;
}
try {
if (i == 9) {
System.out.println(
"Could not contact the VM at localhost" + ":" + fBackEndPort + ".");
}
Thread.sleep(200);
} catch (InterruptedException e2) {
Thread.sleep(10);
} catch (InterruptedException interrupted) {
}
}
}
Expand All @@ -927,6 +932,8 @@ protected void connectToVM() {
}
throw new Error("Could not contact the VM");
}
long n1 = System.nanoTime(); // for example after ~ 110ms
System.out.println("Connected to localhost" + ":" + fBackEndPort + " after " + (n1 - n0) / 1_000_000 + "ms");
startEventReader();
}
/**
Expand Down Expand Up @@ -1187,7 +1194,7 @@ private void startConsoleReaders() {
fLaunchedVM.getInputStream());
} else {
fConsoleReader =
new NullConsoleReader("JDI Tests Console Reader", fLaunchedVM.getInputStream());
new NullConsoleReader("JDI Tests Console Reader", fLaunchedVM.getInputStream(), System.out);
}
fConsoleReader.start();

Expand All @@ -1201,7 +1208,7 @@ private void startConsoleReaders() {
fConsoleErrorReader =
new NullConsoleReader(
"JDI Tests Console Error Reader",
fLaunchedVM.getErrorStream());
fLaunchedVM.getErrorStream(), System.err);
}
fConsoleErrorReader.start();

Expand All @@ -1219,7 +1226,7 @@ private void startConsoleReaders() {
fProxyReader =
new NullConsoleReader(
"JDI Tests Proxy Reader",
fLaunchedProxy.getInputStream());
fLaunchedProxy.getInputStream(), System.out);
}
fProxyReader.start();

Expand All @@ -1233,7 +1240,7 @@ private void startConsoleReaders() {
fProxyErrorReader =
new NullConsoleReader(
"JDI Tests Proxy Error Reader",
fLaunchedProxy.getErrorStream());
fLaunchedProxy.getErrorStream(), System.err);
}
fProxyErrorReader.start();
}
Expand Down Expand Up @@ -1298,21 +1305,24 @@ protected void startProgram() {
fEventReader.start();

// Wait until the program has started
Event event = waitForEvent(waiter, 3 * TIMEOUT);
Event event = waitForEvent(waiter, TIMEOUT);
fEventReader.removeEventListener(waiter);
if (event == null) {
// try {
System.out.println(
"\nThe program doesn't seem to have started after " + (3 * TIMEOUT) + "ms");
// InputStream errorStream = fLaunchedVM.getErrorStream();
// int read;
// do {
// read = errorStream.read();
// if (read != -1)
// System.out.print((char) read);
// } while (read != -1);
// } catch (IOException e) {
// }
"\nThe program doesn't seem to have started after " + TIMEOUT + "ms");
}
// silence streams after "Listening for transport dt_socket at address: xyz"
if (fConsoleErrorReader instanceof NullConsoleReader r) {
r.shutUp();
}
if (fConsoleReader instanceof NullConsoleReader r) {
r.shutUp();
}
if (fProxyReader instanceof NullConsoleReader r) {
r.shutUp();
}
if (fProxyErrorReader instanceof NullConsoleReader r) {
r.shutUp();
}

// Stop class prepare events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
abstract public class AbstractReader {
protected String fName;
protected Thread fReaderThread;
protected boolean fIsStopping = false;
protected volatile boolean fIsStopping = false;

/**
* Constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
*******************************************************************************/
package org.eclipse.debug.jdi.tests;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

/**
* A null console reader that continuously reads from the VM input stream
Expand All @@ -25,26 +24,38 @@

public class NullConsoleReader extends AbstractReader {
private final InputStream fInput;
private volatile PrintStream out;

/**
* Constructor
*
* @param out
*/
public NullConsoleReader(String name, InputStream input) {
public NullConsoleReader(String name, InputStream input, PrintStream out) {
super(name);
fInput = input;
this.out = out;
}
/**
* Continuously reads events that are coming from the event queue.
*/
@Override
protected void readerLoop() {
java.io.BufferedReader input =
new BufferedReader(new InputStreamReader(fInput));
try {
int read = 0;
while (!fIsStopping && read != -1) {
read = input.read();
int size = 0;
byte[] buffer = new byte[1024];
while (!fIsStopping && (size = fInput.read(buffer)) != -1) {
if (out instanceof PrintStream o) {
o.write(buffer, 0, size);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}

public void shutUp() {
this.out = null;
}

}

0 comments on commit 8c1b934

Please sign in to comment.