Author: kristwaa
Date: Thu Oct 6 09:22:29 2011
New Revision: 1179546
URL: http://svn.apache.org/viewvc?rev=1179546&view=rev
Log:
DERBY-5444: SpawnedProcess.complete may fail to destroy the process when a timeout is specified
Rewrote loop logic to ensure that the process is destroyed when a timeout is specified and
exceeded.
Patch file: derby-5444-1c-destroy_on_timeout.diff
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SpawnedProcess.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SpawnedProcess.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SpawnedProcess.java?rev=1179546&r1=1179545&r2=1179546&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SpawnedProcess.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SpawnedProcess.java Thu
Oct 6 09:22:29 2011
@@ -158,23 +158,25 @@ public final class SpawnedProcess {
public int complete(boolean destroy, long timeout) throws InterruptedException, IOException
{
int exitCode;
if (timeout >= 0 ) {
+ final long start = System.currentTimeMillis();
+ boolean timedOut = true;
long totalwait = -1;
while (totalwait < timeout) {
try {
- exitCode = javaProcess.exitValue();
- //if no exception thrown, exited normally
- destroy = false;
- break;
+ exitCode = javaProcess.exitValue();
+ //if no exception thrown, exited normally
+ destroy = timedOut = false;
+ break;
}catch (IllegalThreadStateException ite) {
- if (totalwait >= timeout) {
- destroy = true;
- break;
- } else {
- totalwait += 1000;
- Thread.sleep(1000);
- }
+ // Ignore exception, it means that the process is running.
+ Thread.sleep(1000);
+ totalwait = System.currentTimeMillis() - start;
}
}
+ // If we timed out, make sure we try to destroy the process.
+ if (timedOut) {
+ destroy = true;
+ }
}
if (destroy)
javaProcess.destroy();
|