6402201: ProcessAttachTest.sh needs better synchronization
authoregahlin
Thu, 21 Nov 2013 13:46:35 +0100
changeset 21832 85be6fd8b7be
parent 21831 ccd19d2dc324
child 21833 60a910311eb7
6402201: ProcessAttachTest.sh needs better synchronization Reviewed-by: alanb
jdk/test/ProblemList.txt
jdk/test/com/sun/jdi/ProcessAttachDebuggee.java
jdk/test/com/sun/jdi/ProcessAttachTest.sh
--- a/jdk/test/ProblemList.txt	Thu Nov 21 11:36:39 2013 +0000
+++ b/jdk/test/ProblemList.txt	Thu Nov 21 13:46:35 2013 +0100
@@ -304,9 +304,6 @@
 # Filed 6653793
 com/sun/jdi/RedefineCrossEvent.java                             generic-all
 
-# Filed 6402201
-com/sun/jdi/ProcessAttachTest.sh                                generic-all
-
 ############################################################################
 
 # jdk_util
--- a/jdk/test/com/sun/jdi/ProcessAttachDebuggee.java	Thu Nov 21 11:36:39 2013 +0000
+++ b/jdk/test/com/sun/jdi/ProcessAttachDebuggee.java	Thu Nov 21 13:46:35 2013 +0100
@@ -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 @@
         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();
--- a/jdk/test/com/sun/jdi/ProcessAttachTest.sh	Thu Nov 21 11:36:39 2013 +0000
+++ b/jdk/test/com/sun/jdi/ProcessAttachTest.sh	Thu Nov 21 13:46:35 2013 +0100
@@ -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 @@
 # 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}"