Skip to content

Commit

Permalink
Adding Integ Tests for Granular Stop Timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ubhattacharjya committed Feb 27, 2019
1 parent 314e658 commit 464ff08
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
8 changes: 4 additions & 4 deletions agent/engine/ordering_integ_test.go
Expand Up @@ -75,7 +75,6 @@ func TestDependencyHealthCheck(t *testing.T) {
}()

waitFinished(t, finished, orderingTimeout)

}

// TestDependencyComplete validates that the COMPLETE dependency condition will resolve when the child container exits
Expand All @@ -93,7 +92,7 @@ func TestDependencyComplete(t *testing.T) {
dependency := createTestContainerWithImageAndName(baseImageForOS, "dependency")

parent.EntryPoint = &entryPointForOS
parent.Command = []string{"sleep 5 && exit 0"}
parent.Command = []string{"sleep 5"}
parent.DependsOn = []apicontainer.DependsOn{
{
Container: "dependency",
Expand Down Expand Up @@ -155,7 +154,7 @@ func TestDependencySuccess(t *testing.T) {
}

dependency.EntryPoint = &entryPointForOS
dependency.Command = []string{"sleep 10 && exit 0"}
dependency.Command = []string{"sleep 10"}
dependency.Essential = false

testTask.Containers = []*apicontainer.Container{
Expand Down Expand Up @@ -255,7 +254,7 @@ func TestDependencySuccessTimeout(t *testing.T) {
}

dependency.EntryPoint = &entryPointForOS
dependency.Command = []string{"sleep 15 && exit 0"}
dependency.Command = []string{"sleep 15"}
dependency.Essential = false

// set the timeout to be shorter than the amount of time it takes to stop
Expand Down Expand Up @@ -339,6 +338,7 @@ func TestDependencyHealthyTimeout(t *testing.T) {
waitFinished(t, finished, orderingTimeout)
}


func waitFinished(t *testing.T, finished <-chan interface{}, duration time.Duration) {
select {
case <-finished:
Expand Down
74 changes: 74 additions & 0 deletions agent/engine/ordering_integ_unix_test.go
Expand Up @@ -15,10 +15,84 @@

package engine

import (
"testing"

apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container"
"github.com/stretchr/testify/assert"
)

const (
baseImageForOS = testRegistryHost + "/" + "busybox"
)

var (
entryPointForOS = []string{"sh", "-c"}
)

func TestGranularStopTimeout(t *testing.T) {
taskEngine, done, _ := setupWithDefaultConfig(t)
defer done()

stateChangeEvents := taskEngine.StateChangeEvents()

taskArn := "TestGranularStopTimeout"
testTask := createTestTask(taskArn)

parent := createTestContainerWithImageAndName(baseImageForOS, "parent")
dependency1 := createTestContainerWithImageAndName(baseImageForOS, "dependency1")
dependency2 := createTestContainerWithImageAndName(baseImageForOS, "dependency2")

parent.EntryPoint = &entryPointForOS
parent.Command = []string{"sleep 30"}
parent.Essential = true
parent.DependsOn = []apicontainer.DependsOn{
{
Container: "dependency1",
Condition: "START",
},
{
Container: "dependency2",
Condition: "START",
},
}

dependency1.EntryPoint = &entryPointForOS
dependency1.Command = []string{"trap 'echo caught' SIGTERM; sleep 60"}
dependency1.StopTimeout = 5

dependency2.EntryPoint = &entryPointForOS
dependency2.Command = []string{"trap 'echo caught' SIGTERM; sleep 60"}
dependency2.StopTimeout = 50

testTask.Containers = []*apicontainer.Container{
dependency1,
dependency2,
parent,
}

go taskEngine.AddTask(testTask)

finished := make(chan interface{})
go func() {

verifyContainerRunningStateChange(t, taskEngine)
verifyContainerRunningStateChange(t, taskEngine)
verifyContainerRunningStateChange(t, taskEngine)

verifyTaskIsRunning(stateChangeEvents, testTask)

verifyContainerStoppedStateChange(t, taskEngine)
verifyContainerStoppedStateChange(t, taskEngine)
verifyContainerStoppedStateChange(t, taskEngine)

verifyTaskIsStopped(stateChangeEvents, testTask)

assert.Equal(t, 137, *testTask.Containers[0].GetKnownExitCode(), "Dependency1 should exit with code 137")
assert.Equal(t, 0, *testTask.Containers[1].GetKnownExitCode(), "Dependency2 should exit with code 0")

close(finished)
}()

waitFinished(t, finished, orderingTimeout)
}

0 comments on commit 464ff08

Please sign in to comment.