mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Make events test more deterministic in go1.5
Now scheduler makes order of events pretty random, so I added little sleeps to make order intact. Also I renamed to test so name better describes its nature. Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
parent
f848f34da2
commit
386aefb9fc
1 changed files with 23 additions and 40 deletions
|
@ -1,7 +1,6 @@
|
||||||
package events
|
package events
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -81,55 +80,39 @@ func TestEventsLogTimeout(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLogEvents(t *testing.T) {
|
func TestEventsCap(t *testing.T) {
|
||||||
e := New()
|
e := New()
|
||||||
|
for i := 0; i < eventsLimit+1; i++ {
|
||||||
for i := 0; i < eventsLimit+16; i++ {
|
e.Log("action", "id", "from")
|
||||||
action := fmt.Sprintf("action_%d", i)
|
|
||||||
id := fmt.Sprintf("cont_%d", i)
|
|
||||||
from := fmt.Sprintf("image_%d", i)
|
|
||||||
e.Log(action, id, from)
|
|
||||||
}
|
}
|
||||||
time.Sleep(50 * time.Millisecond)
|
// let all events go through
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
current, l := e.Subscribe()
|
current, l := e.Subscribe()
|
||||||
for i := 0; i < 10; i++ {
|
if len(current) != eventsLimit {
|
||||||
num := i + eventsLimit + 16
|
t.Fatalf("Must be %d events, got %d", eventsLimit, len(current))
|
||||||
action := fmt.Sprintf("action_%d", num)
|
|
||||||
id := fmt.Sprintf("cont_%d", num)
|
|
||||||
from := fmt.Sprintf("image_%d", num)
|
|
||||||
e.Log(action, id, from)
|
|
||||||
}
|
}
|
||||||
if len(e.events) != eventsLimit {
|
if len(e.events) != eventsLimit {
|
||||||
t.Fatalf("Must be %d events, got %d", eventsLimit, len(e.events))
|
t.Fatalf("Must be %d events, got %d", eventsLimit, len(e.events))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
e.Log("action", "id", "from")
|
||||||
|
}
|
||||||
|
// let all events go through
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
var msgs []*jsonmessage.JSONMessage
|
var msgs []*jsonmessage.JSONMessage
|
||||||
for len(msgs) < 10 {
|
for len(msgs) < 10 {
|
||||||
m := <-l
|
select {
|
||||||
jm, ok := (m).(*jsonmessage.JSONMessage)
|
case m := <-l:
|
||||||
if !ok {
|
jm, ok := (m).(*jsonmessage.JSONMessage)
|
||||||
t.Fatalf("Unexpected type %T", m)
|
if !ok {
|
||||||
|
t.Fatalf("Unexpected type %T", m)
|
||||||
|
}
|
||||||
|
msgs = append(msgs, jm)
|
||||||
|
default:
|
||||||
|
t.Fatalf("There is no enough events in channel")
|
||||||
}
|
}
|
||||||
msgs = append(msgs, jm)
|
|
||||||
}
|
|
||||||
if len(current) != eventsLimit {
|
|
||||||
t.Fatalf("Must be %d events, got %d", eventsLimit, len(current))
|
|
||||||
}
|
|
||||||
first := current[0]
|
|
||||||
if first.Status != "action_16" {
|
|
||||||
t.Fatalf("First action is %s, must be action_16", first.Status)
|
|
||||||
}
|
|
||||||
last := current[len(current)-1]
|
|
||||||
if last.Status != "action_79" {
|
|
||||||
t.Fatalf("Last action is %s, must be action_79", last.Status)
|
|
||||||
}
|
|
||||||
|
|
||||||
firstC := msgs[0]
|
|
||||||
if firstC.Status != "action_80" {
|
|
||||||
t.Fatalf("First action is %s, must be action_80", firstC.Status)
|
|
||||||
}
|
|
||||||
lastC := msgs[len(msgs)-1]
|
|
||||||
if lastC.Status != "action_89" {
|
|
||||||
t.Fatalf("Last action is %s, must be action_89", lastC.Status)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue