Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a couple tests; fix test-in-docker #49

Merged
merged 2 commits into from
Apr 10, 2015
Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions agent/engine/docker_container_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ func (dg *DockerGoClient) ContainerEvents() (<-chan DockerContainerChangeEvent,
case "export":

// Image events
case "pull":
case "untag":
case "delete":
default:
Expand Down
30 changes: 30 additions & 0 deletions agent/engine/dockerstate/dockerstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
5 changes: 5 additions & 0 deletions agent/engine/engine_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
21 changes: 21 additions & 0 deletions agent/eventhandler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
15 changes: 10 additions & 5 deletions agent/eventhandler/task_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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")
}
}
}

Expand Down
10 changes: 3 additions & 7 deletions scripts/dockerfiles/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
5 changes: 4 additions & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -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