aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoregahlin <none@none>2013-11-21 13:46:35 +0100
committeregahlin <none@none>2013-11-21 13:46:35 +0100
commitf1cc0d9d796a9c2ed6e620a03eee342863049db6 (patch)
tree73c282e494b71a49ac242caf06a064b328c75344 /test
parent214cbfb0146cbfc365183e94bcdeebb6e5547681 (diff)
6402201: ProcessAttachTest.sh needs better synchronization
Reviewed-by: alanb
Diffstat (limited to 'test')
-rw-r--r--test/ProblemList.txt3
-rw-r--r--test/com/sun/jdi/ProcessAttachDebuggee.java15
-rw-r--r--test/com/sun/jdi/ProcessAttachTest.sh14
3 files changed, 22 insertions, 10 deletions
diff --git a/test/ProblemList.txt b/test/ProblemList.txt
index 7c7c84ceb..f9584473f 100644
--- a/test/ProblemList.txt
+++ b/test/ProblemList.txt
@@ -304,9 +304,6 @@ com/sun/jdi/SuspendThreadTest.java generic-all
# Filed 6653793
com/sun/jdi/RedefineCrossEvent.java generic-all
-# Filed 6402201
-com/sun/jdi/ProcessAttachTest.sh generic-all
-
############################################################################
# jdk_util
diff --git a/test/com/sun/jdi/ProcessAttachDebuggee.java b/test/com/sun/jdi/ProcessAttachDebuggee.java
index feca08822..3208b1551 100644
--- a/test/com/sun/jdi/ProcessAttachDebuggee.java
+++ b/test/com/sun/jdi/ProcessAttachDebuggee.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2013, 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
@@ -29,6 +29,9 @@
*/
import java.net.Socket;
import java.net.ServerSocket;
+import java.nio.file.CopyOption;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
import java.io.File;
import java.io.FileOutputStream;
@@ -39,10 +42,12 @@ public class ProcessAttachDebuggee {
int port = ss.getLocalPort();
// Write the port number to the given file
- File f = new File(args[0]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.write( Integer.toString(port).getBytes("UTF-8") );
- fos.close();
+ File partial = new File(args[0] + ".partial");
+ File portFile = new File(args[0]);
+ try (FileOutputStream fos = new FileOutputStream(partial)) {
+ fos.write( Integer.toString(port).getBytes("UTF-8") );
+ }
+ Files.move(partial.toPath(), portFile.toPath(), StandardCopyOption.ATOMIC_MOVE);
System.out.println("Debuggee bound to port: " + port);
System.out.flush();
diff --git a/test/com/sun/jdi/ProcessAttachTest.sh b/test/com/sun/jdi/ProcessAttachTest.sh
index d48ea5ec8..10b5d5031 100644
--- a/test/com/sun/jdi/ProcessAttachTest.sh
+++ b/test/com/sun/jdi/ProcessAttachTest.sh
@@ -1,7 +1,7 @@
#!/bin/sh
#
-# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2005, 2013, 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
@@ -158,7 +158,17 @@ $JAVA -classpath "${TESTCLASSES}${PS}${TESTJAVA}/lib/tools.jar" \
# The debuggee is suspended and doesn't run until the debugger
# disconnects. We have to give it time to write the port number
# to ${PORTFILE}
-sleep 10
+
+echo "Waiting for port file to be written..."
+attempts=0
+while true; do
+ sleep 1
+ attempts=`expr $attempts + 1`
+ if [ -f ${PORTFILE} ]; then
+ break
+ fi
+ echo "Waiting $attempts second(s) ..."
+done
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
stopDebuggee "${PORTFILE}"