Merge pull request #6918 from vieux/rebase_events_leak

Rebase events leak
This commit is contained in:
Victor Vieux 2014-07-08 17:18:09 -07:00
commit bdf7224941
2 changed files with 23 additions and 2 deletions

View file

@ -3,6 +3,7 @@ package main
import (
"fmt"
"os/exec"
"strconv"
"strings"
"testing"
"time"
@ -55,3 +56,17 @@ func TestCLIGetEventsPause(t *testing.T) {
logDone("events - pause/unpause is logged")
}
func TestCLILimitEvents(t *testing.T) {
for i := 0; i < 30; i++ {
cmd(t, "run", "busybox", "echo", strconv.Itoa(i))
}
eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", time.Now().Unix()))
out, _, _ := runCommandWithOutput(eventsCmd)
events := strings.Split(out, "\n")
n_events := len(events) - 1
if n_events != 64 {
t.Fatalf("events should be limited to 64, but received %d", n_events)
}
logDone("events - limited to 64 entries")
}

View file

@ -2463,8 +2463,14 @@ func (srv *Server) LogEvent(action, id, from string) *utils.JSONMessage {
func (srv *Server) AddEvent(jm utils.JSONMessage) {
srv.Lock()
defer srv.Unlock()
if len(srv.events) == cap(srv.events) {
// discard oldest event
copy(srv.events, srv.events[1:])
srv.events[len(srv.events)-1] = jm
} else {
srv.events = append(srv.events, jm)
}
srv.Unlock()
}
func (srv *Server) GetEvents() []utils.JSONMessage {