Skip to content

Commit 46ef719

Browse files
committed
Merge pull request #49 from euank/misc
Add a couple tests; fix test-in-docker
2 parents 4023248 + 1e7cd33 commit 46ef719

File tree

8 files changed

+75
-14
lines changed

8 files changed

+75
-14
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ volumes-test:
8484

8585
get-deps:
8686
go get github.com/tools/godep
87-
go get golang.org/x/tools/cover
87+
go get golang.org/x/tools/cmd/cover
8888
go get code.google.com/p/gomock/mockgen
8989

9090
clean:

agent/engine/docker_container_engine.go

+1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ func (dg *DockerGoClient) ContainerEvents() (<-chan DockerContainerChangeEvent,
363363
case "export":
364364

365365
// Image events
366+
case "pull":
366367
case "untag":
367368
case "delete":
368369
default:

agent/engine/dockerstate/dockerstate_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,33 @@ func TestTwophaseAddContainer(t *testing.T) {
121121
t.Fatal("Incorrect container fetched")
122122
}
123123
}
124+
125+
func TestRemoveTask(t *testing.T) {
126+
state := NewDockerTaskEngineState()
127+
testContainer := &api.Container{
128+
Name: "c1",
129+
}
130+
testDockerContainer := &api.DockerContainer{
131+
DockerId: "did",
132+
Container: testContainer,
133+
}
134+
testTask := &api.Task{
135+
Arn: "t1",
136+
Containers: []*api.Container{testContainer},
137+
}
138+
139+
state.AddOrUpdateTask(testTask)
140+
state.AddContainer(testDockerContainer, testTask)
141+
142+
tasks := state.AllTasks()
143+
if len(tasks) != 1 {
144+
t.Error("Expected only 1 task")
145+
}
146+
147+
state.RemoveTask(testTask)
148+
149+
tasks = state.AllTasks()
150+
if len(tasks) != 0 {
151+
t.Error("Expected task to be removed")
152+
}
153+
}

agent/engine/engine_integ_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -901,4 +901,9 @@ func TestSweepContainer(t *testing.T) {
901901
if ok {
902902
t.Error("Expected container to have been sweept but was not")
903903
}
904+
905+
allTasks := taskEngine.(*DockerTaskEngine).State().AllTasks()
906+
if len(allTasks) != 0 {
907+
t.Error("Sweep did not remove all containers")
908+
}
904909
}

agent/eventhandler/handler_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,24 @@ func TestSendsEvents(t *testing.T) {
337337
default:
338338
}
339339
}
340+
341+
func TestShouldBeSent(t *testing.T) {
342+
sendableEvent := newSendableEvent(api.ContainerStateChange{
343+
Status: api.ContainerStopped,
344+
TaskStatus: api.TaskStatusNone,
345+
Container: &api.Container{},
346+
})
347+
348+
if sendableEvent.taskShouldBeSent() {
349+
t.Error("TasStatusNone should not be sent")
350+
}
351+
352+
if !sendableEvent.containerShouldBeSent() {
353+
t.Error("Container should be sent if it's the first try")
354+
}
355+
356+
sendableEvent = newSendableEvent(api.ContainerStateChange{
357+
Status: api.ContainerStopped,
358+
TaskStatus: api.TaskStatusNone,
359+
})
360+
}

agent/eventhandler/task_handler.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ func SubmitTaskEvents(events *eventList, client api.ECSClient) {
108108
event.containerSent = true
109109
event.Container.SentStatus = event.Status
110110
statesaver.Save()
111-
llog.Debug("Submitted container")
112-
} else {
113-
llog.Error("Unretriable error submitting container state change", "err", contErr)
111+
if contErr != nil {
112+
llog.Error("Unretriable error submitting container state change", "err", contErr)
113+
} else {
114+
llog.Debug("Submitted container")
115+
}
114116
}
115117
}
116118
if event.taskShouldBeSent() {
@@ -121,8 +123,11 @@ func SubmitTaskEvents(events *eventList, client api.ECSClient) {
121123
event.taskSent = true
122124
event.Task.SentStatus = event.TaskStatus
123125
statesaver.Save()
124-
} else {
125-
llog.Error("Error submitting task state change", "err", taskErr)
126+
if taskErr != nil {
127+
llog.Error("Unretriable error submitting container state change", "err", contErr)
128+
} else {
129+
llog.Debug("Submitted container")
130+
}
126131
}
127132
}
128133

scripts/dockerfiles/Dockerfile.test

+3-7
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ WORKDIR /go
5353
# Dockerfile.build should INCLUDE a common source. Same is true for the above
5454
# section.
5555
RUN mkdir -p /go/src/github.com/aws/
56-
WORKDIR /go/src/github.com/aws/amazon-ecs-agent/
57-
RUN make get-deps
58-
59-
WORKDIR /go/src/github.com/aws/amazon-ecs-agent/agent
60-
61-
62-
ENTRYPOINT /go/src/github.com/aws/amazon-ecs-agent/scripts/test
56+
WORKDIR /go/src/github.com/aws/amazon-ecs-agent
57+
COPY scripts/test /entrypoint
58+
ENTRYPOINT ["/entrypoint"]

scripts/test

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ DOCKER_DAEMON_ARGS="--insecure-registry 127.0.0.1:51671 --insecure-registry 127.
1717

1818
sleep 2
1919

20+
make get-deps
21+
cd agent
2022
export GOPATH=`godep path`:$GOPATH
21-
cd ..; make get-deps; make test
23+
cd ..
24+
make test

0 commit comments

Comments
 (0)