Skip to content

Commit 1d245c6

Browse files
author
Alex Menkov
committed
8252117: com/sun/jdi/BadHandshakeTest.java failed with "ConnectException: Connection refused: connect"
Reviewed-by: cjplummer, sspitsyn
1 parent 7a7ce02 commit 1d245c6

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

test/jdk/com/sun/jdi/BadHandshakeTest.java

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -112,28 +112,51 @@ public static void main(String args[]) throws Exception {
112112
throw error;
113113
}
114114

115-
log("cleaning...");
116-
// Attach to server debuggee and resume it so it can exit
115+
log("final attach...");
116+
// Attach to server debuggee to ensure it's still available to attach and resume it so it can exit
117117
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
118-
Map<String, Argument> conn_args = conn.defaultArguments();
119-
Connector.IntegerArgument port_arg =
120-
(Connector.IntegerArgument)conn_args.get("port");
121-
port_arg.setValue(port);
122-
VirtualMachine vm = conn.attach(conn_args);
118+
retryDelay = 20;
119+
for (int retry = 0; retry < 5; retry++) {
120+
if (error != null) {
121+
try {
122+
Thread.sleep(retryDelay);
123+
} catch (InterruptedException ex) {
124+
// ignore
125+
}
126+
retryDelay *= 2;
127+
error = null;
128+
}
129+
try {
130+
log("retry: " + retry);
131+
Map<String, Argument> conn_args = conn.defaultArguments();
132+
Connector.IntegerArgument port_arg =
133+
(Connector.IntegerArgument)conn_args.get("port");
134+
port_arg.setValue(port);
135+
VirtualMachine vm = conn.attach(conn_args);
136+
137+
// The first event is always a VMStartEvent, and it is always in
138+
// an EventSet by itself. Wait for it.
139+
EventSet evtSet = vm.eventQueue().remove();
140+
for (Event event : evtSet) {
141+
if (event instanceof VMStartEvent) {
142+
break;
143+
}
144+
throw new RuntimeException("Test failed - debuggee did not start properly");
145+
}
123146

124-
// The first event is always a VMStartEvent, and it is always in
125-
// an EventSet by itself. Wait for it.
126-
EventSet evtSet = vm.eventQueue().remove();
127-
for (Event event : evtSet) {
128-
if (event instanceof VMStartEvent) {
147+
vm.eventRequestManager().deleteAllBreakpoints();
148+
vm.resume();
129149
break;
150+
} catch (ConnectException ex) {
151+
log("got exception: " + ex.toString());
152+
error = ex;
130153
}
131-
throw new RuntimeException("Test failed - debuggee did not start properly");
154+
}
155+
if (error != null) {
156+
throw error;
132157
}
133158

134-
vm.eventRequestManager().deleteAllBreakpoints();
135-
vm.resume();
136-
159+
// give the debuggee some time to exit before forcibly terminating it
137160
debuggee.waitFor(10, TimeUnit.SECONDS);
138161
}
139162
}

0 commit comments

Comments
 (0)