Skip to content

Commit

Permalink
8252117: com/sun/jdi/BadHandshakeTest.java failed with "ConnectExcept…
Browse files Browse the repository at this point in the history
…ion: Connection refused: connect"

Reviewed-by: cjplummer, sspitsyn
  • Loading branch information
Alex Menkov committed Oct 27, 2020
1 parent 7a7ce02 commit 1d245c6
Showing 1 changed file with 40 additions and 17 deletions.
57 changes: 40 additions & 17 deletions test/jdk/com/sun/jdi/BadHandshakeTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -112,28 +112,51 @@ public static void main(String args[]) throws Exception {
throw error;
}

log("cleaning...");
// Attach to server debuggee and resume it so it can exit
log("final attach...");
// Attach to server debuggee to ensure it's still available to attach and resume it so it can exit
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
Map<String, Argument> conn_args = conn.defaultArguments();
Connector.IntegerArgument port_arg =
(Connector.IntegerArgument)conn_args.get("port");
port_arg.setValue(port);
VirtualMachine vm = conn.attach(conn_args);
retryDelay = 20;
for (int retry = 0; retry < 5; retry++) {
if (error != null) {
try {
Thread.sleep(retryDelay);
} catch (InterruptedException ex) {
// ignore
}
retryDelay *= 2;
error = null;
}
try {
log("retry: " + retry);
Map<String, Argument> conn_args = conn.defaultArguments();
Connector.IntegerArgument port_arg =
(Connector.IntegerArgument)conn_args.get("port");
port_arg.setValue(port);
VirtualMachine vm = conn.attach(conn_args);

// The first event is always a VMStartEvent, and it is always in
// an EventSet by itself. Wait for it.
EventSet evtSet = vm.eventQueue().remove();
for (Event event : evtSet) {
if (event instanceof VMStartEvent) {
break;
}
throw new RuntimeException("Test failed - debuggee did not start properly");
}

// The first event is always a VMStartEvent, and it is always in
// an EventSet by itself. Wait for it.
EventSet evtSet = vm.eventQueue().remove();
for (Event event : evtSet) {
if (event instanceof VMStartEvent) {
vm.eventRequestManager().deleteAllBreakpoints();
vm.resume();
break;
} catch (ConnectException ex) {
log("got exception: " + ex.toString());
error = ex;
}
throw new RuntimeException("Test failed - debuggee did not start properly");
}
if (error != null) {
throw error;
}

vm.eventRequestManager().deleteAllBreakpoints();
vm.resume();

// give the debuggee some time to exit before forcibly terminating it
debuggee.waitFor(10, TimeUnit.SECONDS);
}
}
Expand Down

1 comment on commit 1d245c6

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 1d245c6 Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.