mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fixes docker events since beginning of unix time
Fixes issue #11555 Applied a workaround to check if since and until flags are valid or not. Signed-off-by: André Martins <martins@noironetworks.com>
This commit is contained in:
parent
39711c8b26
commit
8f7ac20bac
2 changed files with 37 additions and 2 deletions
|
@ -59,7 +59,7 @@ func (e *Events) Get(job *engine.Job) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no until, disable timeout
|
// If no until, disable timeout
|
||||||
if until == 0 {
|
if job.Getenv("until") == "" {
|
||||||
timeout.Stop()
|
timeout.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ func (e *Events) Get(job *engine.Job) error {
|
||||||
job.Stdout.Write(nil)
|
job.Stdout.Write(nil)
|
||||||
|
|
||||||
// Resend every event in the [since, until] time interval.
|
// Resend every event in the [since, until] time interval.
|
||||||
if since != 0 {
|
if job.Getenv("since") != "" {
|
||||||
if err := e.writeCurrent(job, since, until, eventFilters); err != nil {
|
if err := e.writeCurrent(job, since, until, eventFilters); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,6 +112,41 @@ func TestEventsContainerEvents(t *testing.T) {
|
||||||
logDone("events - container create, start, die, destroy is logged")
|
logDone("events - container create, start, die, destroy is logged")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEventsContainerEventsSinceUnixEpoch(t *testing.T) {
|
||||||
|
dockerCmd(t, "run", "--rm", "busybox", "true")
|
||||||
|
timeBeginning := time.Unix(0, 0).Format(time.RFC3339Nano)
|
||||||
|
timeBeginning = strings.Replace(timeBeginning, "Z", ".000000000Z", -1)
|
||||||
|
eventsCmd := exec.Command(dockerBinary, "events", fmt.Sprintf("--since='%s'", timeBeginning),
|
||||||
|
fmt.Sprintf("--until=%d", daemonTime(t).Unix()))
|
||||||
|
out, exitCode, err := runCommandWithOutput(eventsCmd)
|
||||||
|
if exitCode != 0 || err != nil {
|
||||||
|
t.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
|
||||||
|
}
|
||||||
|
events := strings.Split(out, "\n")
|
||||||
|
events = events[:len(events)-1]
|
||||||
|
if len(events) < 4 {
|
||||||
|
t.Fatalf("Missing expected event")
|
||||||
|
}
|
||||||
|
createEvent := strings.Fields(events[len(events)-4])
|
||||||
|
startEvent := strings.Fields(events[len(events)-3])
|
||||||
|
dieEvent := strings.Fields(events[len(events)-2])
|
||||||
|
destroyEvent := strings.Fields(events[len(events)-1])
|
||||||
|
if createEvent[len(createEvent)-1] != "create" {
|
||||||
|
t.Fatalf("event should be create, not %#v", createEvent)
|
||||||
|
}
|
||||||
|
if startEvent[len(startEvent)-1] != "start" {
|
||||||
|
t.Fatalf("event should be start, not %#v", startEvent)
|
||||||
|
}
|
||||||
|
if dieEvent[len(dieEvent)-1] != "die" {
|
||||||
|
t.Fatalf("event should be die, not %#v", dieEvent)
|
||||||
|
}
|
||||||
|
if destroyEvent[len(destroyEvent)-1] != "destroy" {
|
||||||
|
t.Fatalf("event should be destroy, not %#v", destroyEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("events - container create, start, die, destroy since Unix Epoch time")
|
||||||
|
}
|
||||||
|
|
||||||
func TestEventsImageUntagDelete(t *testing.T) {
|
func TestEventsImageUntagDelete(t *testing.T) {
|
||||||
name := "testimageevents"
|
name := "testimageevents"
|
||||||
defer deleteImages(name)
|
defer deleteImages(name)
|
||||||
|
|
Loading…
Reference in a new issue