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

Check the sentstatus before updating #1383

Merged
merged 2 commits into from
May 11, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Feature - Configurable container image pull behavior [#1348](https://github.com/aws/amazon-ecs-agent/pull/1348)
* Bug - Fixed a bug where Docker Version() API never returns by adding a timeout [#1363](https://github.com/aws/amazon-ecs-agent/pull/1363)
* Bug - Fixed a bug where tasks could get stuck waiting for execution of CNI plugin [#1358](https://github.com/aws/amazon-ecs-agent/pull/1358)
* Bug - Fixed a bug where task cleanup could be blocked due to incorrect sentstatus [#1383](https://github.com/aws/amazon-ecs-agent/pull/1383)

## 1.17.3
* Enhancement - Distinct startContainerTimeouts for windows/linux, introduce a new environment variable `ECS_CONTAINER_START_TIMEOUT` to make it configurable [#1321](https://github.com/aws/amazon-ecs-agent/pull/1321)
Expand Down
17 changes: 12 additions & 5 deletions agent/eventhandler/task_handler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,26 @@ type setStatusSent func(event *sendableEvent)

// setContainerChangeSent sets the event's container change object as sent
func setContainerChangeSent(event *sendableEvent) {
if event.containerChange.Container != nil {
event.containerChange.Container.SetSentStatus(event.containerChange.Status)
containerChangeStatus := event.containerChange.Status
container := event.containerChange.Container
if container != nil && container.GetSentStatus() < containerChangeStatus {
container.SetSentStatus(containerChangeStatus)
}
}

// setTaskChangeSent sets the event's task change object as sent
func setTaskChangeSent(event *sendableEvent) {
if event.taskChange.Task != nil {
event.taskChange.Task.SetSentStatus(event.taskChange.Status)
taskChangeStatus := event.taskChange.Status
task := event.taskChange.Task
if task != nil && task.GetSentStatus() < taskChangeStatus {
task.SetSentStatus(taskChangeStatus)
}
for _, containerStateChange := range event.taskChange.Containers {
container := containerStateChange.Container
container.SetSentStatus(containerStateChange.Status)
containerChangeStatus := containerStateChange.Status
if container.GetSentStatus() < containerChangeStatus {
container.SetSentStatus(containerStateChange.Status)
}
}
}

Expand Down
51 changes: 51 additions & 0 deletions agent/eventhandler/task_handler_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,54 @@ func TestShouldTaskAttachmentEventBeSent(t *testing.T) {
})
}
}

func TestSetTaskSentStatus(t *testing.T) {
testContainer := &api.Container{}
testTask := &api.Task{}

taskRunningStateChange := newSendableTaskEvent(api.TaskStateChange{
Status: api.TaskRunning,
Task: testTask,
Containers: []api.ContainerStateChange{
{
Status: api.ContainerRunning,
Container: testContainer,
},
},
})
taskStoppedStateChange := newSendableTaskEvent(api.TaskStateChange{
Status: api.TaskStopped,
Task: testTask,
Containers: []api.ContainerStateChange{
{
Status: api.ContainerStopped,
Container: testContainer,
},
},
})

setTaskChangeSent(taskStoppedStateChange)
assert.Equal(t, testTask.GetSentStatus(), api.TaskStopped)
assert.Equal(t, testContainer.GetSentStatus(), api.ContainerStopped)
setTaskChangeSent(taskRunningStateChange)
assert.Equal(t, testTask.GetSentStatus(), api.TaskStopped)
assert.Equal(t, testContainer.GetSentStatus(), api.ContainerStopped)
}

func TestSetContainerSentStatus(t *testing.T) {
testContainer := &api.Container{}

containerRunningStateChange := newSendableContainerEvent(api.ContainerStateChange{
Status: api.ContainerRunning,
Container: testContainer,
})
containerStoppedStateChange := newSendableContainerEvent(api.ContainerStateChange{
Status: api.ContainerStopped,
Container: testContainer,
})

setContainerChangeSent(containerStoppedStateChange)
assert.Equal(t, testContainer.GetSentStatus(), api.ContainerStopped)
setContainerChangeSent(containerRunningStateChange)
assert.Equal(t, testContainer.GetSentStatus(), api.ContainerStopped)
}