From 1d245c6ec824c19d24793e00bfedc92a11c18041 Mon Sep 17 00:00:00 2001 From: Alex Menkov Date: Tue, 27 Oct 2020 19:49:38 +0000 Subject: [PATCH] 8252117: com/sun/jdi/BadHandshakeTest.java failed with "ConnectException: Connection refused: connect" Reviewed-by: cjplummer, sspitsyn --- test/jdk/com/sun/jdi/BadHandshakeTest.java | 57 +++++++++++++++------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/test/jdk/com/sun/jdi/BadHandshakeTest.java b/test/jdk/com/sun/jdi/BadHandshakeTest.java index 40bac30561de2..f2b975ecfcc39 100644 --- a/test/jdk/com/sun/jdi/BadHandshakeTest.java +++ b/test/jdk/com/sun/jdi/BadHandshakeTest.java @@ -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 @@ -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 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 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); } }