diff --git a/Makefile b/Makefile index 05ef0777d72..b9822f7a491 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,7 @@ volumes-test: get-deps: go get github.com/tools/godep - go get golang.org/x/tools/cover + go get golang.org/x/tools/cmd/cover go get code.google.com/p/gomock/mockgen clean: diff --git a/agent/engine/docker_container_engine.go b/agent/engine/docker_container_engine.go index 545c5f6e982..ef33d8d371d 100644 --- a/agent/engine/docker_container_engine.go +++ b/agent/engine/docker_container_engine.go @@ -363,6 +363,7 @@ func (dg *DockerGoClient) ContainerEvents() (<-chan DockerContainerChangeEvent, case "export": // Image events + case "pull": case "untag": case "delete": default: diff --git a/agent/engine/dockerstate/dockerstate_test.go b/agent/engine/dockerstate/dockerstate_test.go index 63aa5131d34..7e5792dfc35 100644 --- a/agent/engine/dockerstate/dockerstate_test.go +++ b/agent/engine/dockerstate/dockerstate_test.go @@ -121,3 +121,33 @@ func TestTwophaseAddContainer(t *testing.T) { t.Fatal("Incorrect container fetched") } } + +func TestRemoveTask(t *testing.T) { + state := NewDockerTaskEngineState() + testContainer := &api.Container{ + Name: "c1", + } + testDockerContainer := &api.DockerContainer{ + DockerId: "did", + Container: testContainer, + } + testTask := &api.Task{ + Arn: "t1", + Containers: []*api.Container{testContainer}, + } + + state.AddOrUpdateTask(testTask) + state.AddContainer(testDockerContainer, testTask) + + tasks := state.AllTasks() + if len(tasks) != 1 { + t.Error("Expected only 1 task") + } + + state.RemoveTask(testTask) + + tasks = state.AllTasks() + if len(tasks) != 0 { + t.Error("Expected task to be removed") + } +} diff --git a/agent/engine/engine_integ_test.go b/agent/engine/engine_integ_test.go index 9ea4bdc0776..dedf55a83c8 100644 --- a/agent/engine/engine_integ_test.go +++ b/agent/engine/engine_integ_test.go @@ -901,4 +901,9 @@ func TestSweepContainer(t *testing.T) { if ok { t.Error("Expected container to have been sweept but was not") } + + allTasks := taskEngine.(*DockerTaskEngine).State().AllTasks() + if len(allTasks) != 0 { + t.Error("Sweep did not remove all containers") + } } diff --git a/agent/eventhandler/handler_test.go b/agent/eventhandler/handler_test.go index 9d4adf6d20e..75a21423973 100644 --- a/agent/eventhandler/handler_test.go +++ b/agent/eventhandler/handler_test.go @@ -337,3 +337,24 @@ func TestSendsEvents(t *testing.T) { default: } } + +func TestShouldBeSent(t *testing.T) { + sendableEvent := newSendableEvent(api.ContainerStateChange{ + Status: api.ContainerStopped, + TaskStatus: api.TaskStatusNone, + Container: &api.Container{}, + }) + + if sendableEvent.taskShouldBeSent() { + t.Error("TasStatusNone should not be sent") + } + + if !sendableEvent.containerShouldBeSent() { + t.Error("Container should be sent if it's the first try") + } + + sendableEvent = newSendableEvent(api.ContainerStateChange{ + Status: api.ContainerStopped, + TaskStatus: api.TaskStatusNone, + }) +} diff --git a/agent/eventhandler/task_handler.go b/agent/eventhandler/task_handler.go index 05679126702..30831eab890 100644 --- a/agent/eventhandler/task_handler.go +++ b/agent/eventhandler/task_handler.go @@ -108,9 +108,11 @@ func SubmitTaskEvents(events *eventList, client api.ECSClient) { event.containerSent = true event.Container.SentStatus = event.Status statesaver.Save() - llog.Debug("Submitted container") - } else { - llog.Error("Unretriable error submitting container state change", "err", contErr) + if contErr != nil { + llog.Error("Unretriable error submitting container state change", "err", contErr) + } else { + llog.Debug("Submitted container") + } } } if event.taskShouldBeSent() { @@ -121,8 +123,11 @@ func SubmitTaskEvents(events *eventList, client api.ECSClient) { event.taskSent = true event.Task.SentStatus = event.TaskStatus statesaver.Save() - } else { - llog.Error("Error submitting task state change", "err", taskErr) + if taskErr != nil { + llog.Error("Unretriable error submitting container state change", "err", contErr) + } else { + llog.Debug("Submitted container") + } } } diff --git a/scripts/dockerfiles/Dockerfile.test b/scripts/dockerfiles/Dockerfile.test index 26e1087820d..cd82846d2ec 100644 --- a/scripts/dockerfiles/Dockerfile.test +++ b/scripts/dockerfiles/Dockerfile.test @@ -53,10 +53,6 @@ WORKDIR /go # Dockerfile.build should INCLUDE a common source. Same is true for the above # section. RUN mkdir -p /go/src/github.com/aws/ -WORKDIR /go/src/github.com/aws/amazon-ecs-agent/ -RUN make get-deps - -WORKDIR /go/src/github.com/aws/amazon-ecs-agent/agent - - -ENTRYPOINT /go/src/github.com/aws/amazon-ecs-agent/scripts/test +WORKDIR /go/src/github.com/aws/amazon-ecs-agent +COPY scripts/test /entrypoint +ENTRYPOINT ["/entrypoint"] diff --git a/scripts/test b/scripts/test index 76bf13b7f84..07492b040d8 100755 --- a/scripts/test +++ b/scripts/test @@ -17,5 +17,8 @@ DOCKER_DAEMON_ARGS="--insecure-registry 127.0.0.1:51671 --insecure-registry 127. sleep 2 +make get-deps +cd agent export GOPATH=`godep path`:$GOPATH -cd ..; make get-deps; make test +cd .. +make test