Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Augment test termination timeout test
Browse files Browse the repository at this point in the history
 * Fix race condition in terminate test using healthchecks
 * Make sure we don't terminate too quickly
  • Loading branch information
sargun committed May 18, 2018
1 parent 3735041 commit 029f564
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
42 changes: 32 additions & 10 deletions executor/mock/standalone/standalone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var (
}
ignoreSignals = testImage{
name: "titusoss/ignore-signals",
tag: "20180501-1525157636",
tag: "latest",
}
pty = testImage{
name: "titusoss/pty",
Expand Down Expand Up @@ -94,6 +94,7 @@ func TestStandalone(t *testing.T) {
testMakesPTY,
testOOMAdj,
testOOMKill,
testTerminateTimeoutNotTooFast,
}
for _, fun := range testFunctions {
fullName := runtime.FuncForPC(reflect.ValueOf(fun).Pointer()).Name()
Expand Down Expand Up @@ -476,40 +477,61 @@ func testTerminateTimeout(t *testing.T, jobID string) {
ji := &mock.JobInput{
ImageName: ignoreSignals.name,
Version: ignoreSignals.tag,
KillWaitSeconds: 20,
KillWaitSeconds: 15,
JobID: jobID,
}
jobResponse := jobRunner.StartJob(ji)

// Wait until the task is running
for {
status := <-jobResponse.UpdateChan
if status.State.String() == "TASK_RUNNING" {
for status := range jobResponse.UpdateChan {
if mock.IsTerminalState(status.State) {
t.Fatal("Task exited prematurely (before becoming healthy)")
}
log.Infof("Received status update %+v", status)
if status.State.String() == "TASK_RUNNING" && strings.Contains(status.Mesg, "health_status: healthy") {
break
}
}

// Submit a request to kill the job. Since the
// job does not exit on SIGTERM we expect the kill
// to take at least 20 seconds
// to take at least some seconds
killTime := time.Now()
if err := jobRunner.KillTask(); err != nil {
t.Fail()
}

for status := range jobResponse.UpdateChan {

if mock.IsTerminalState(status.State) {
if status.State.String() != "TASK_KILLED" {
t.Fail()
}
if time.Since(killTime) < 20*time.Second {
t.Fatal("Task was killed too quickly")

killTime := time.Since(killTime)
if killTime < time.Second*time.Duration(ji.KillWaitSeconds) {
t.Fatalf("Task was killed too quickly, in %s", killTime.String())
}
return
}
}
t.Fail()
}

func testTerminateTimeoutNotTooFast(t *testing.T, jobID string) {
// Start the executor
jobRunner := mock.NewJobRunner()
defer jobRunner.StopExecutorAsync()

// Submit a job that runs for a long time and does
// NOT exit on SIGTERM
ji := &mock.JobInput{
ImageName: ignoreSignals.name,
Version: ignoreSignals.tag,
KillWaitSeconds: 35,
JobID: jobID,
}
if !mock.RunJobExpectingSuccess(ji) {
t.Fail()
}
}

func testOOMAdj(t *testing.T, jobID string) {
Expand Down
2 changes: 2 additions & 0 deletions hack/test-images/ignore-signals/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM ubuntu:xenial
COPY trap.sh /
RUN chmod 755 /trap.sh
STOPSIGNAL SIGTERM
HEALTHCHECK --timeout=5s --interval=1s --start-period=1s CMD cat /tmp/foo
CMD ["/trap.sh"]
3 changes: 2 additions & 1 deletion hack/test-images/ignore-signals/trap.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
trap '' SIGINT SIGTERM
sleep 120
touch /tmp/foo
sleep 30
echo completed normally

0 comments on commit 029f564

Please sign in to comment.