Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ public void kill() throws IOException, InterruptedException {
} catch (IOException e) {
LOGGER.log(Level.FINE, "Proc kill failed, ignoring", e);
} finally {
close();
try {
close();
} finally {
// Force finish finished latch count down to ensure join unblocks.
// In the wild it has been observed that sometimes the countdown
// latch is not triggered resulting in joinWithTimeout never
// completing even after the timeout interruption has been triggered.
finished.countDown();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.csanchez.jenkins.plugins.kubernetes.pipeline;

import hudson.model.TaskListener;
import io.fabric8.kubernetes.client.dsl.ExecWatch;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.jvnet.hudson.test.JenkinsRule;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class ContainerExecProcTest {

@Mock
private ExecWatch execWatch;

@Rule
public JenkinsRule j = new JenkinsRule();

/**
* This test validates that {@link hudson.Proc#joinWithTimeout(long, TimeUnit, TaskListener)} is
* terminated properly when the finished count down latch is never triggered by the watch.
*/
@Test(timeout = 20000)
public void testJoinWithTimeoutFinishCountDown() throws Exception {
AtomicBoolean alive = new AtomicBoolean(true);
CountDownLatch finished = new CountDownLatch(1);
ByteArrayOutputStream stdin = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(new ByteArrayOutputStream());
TaskListener listener = TaskListener.NULL;
ContainerExecProc proc = new ContainerExecProc(execWatch, alive, finished, stdin, ps);
proc.joinWithTimeout(1, TimeUnit.SECONDS, listener);
}
}
Loading