This reverts commit 386aefb9fcf65f1a5f68fd61e5108ea0858d2d3f.
Signed-off-by: Vincent Batts <vbatts@redhat.com>
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package events |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "fmt" |
|
| 4 | 5 |
"testing" |
| 5 | 6 |
"time" |
| 6 | 7 |
|
| ... | ... |
@@ -80,39 +81,55 @@ func TestEventsLogTimeout(t *testing.T) {
|
| 80 | 80 |
} |
| 81 | 81 |
} |
| 82 | 82 |
|
| 83 |
-func TestEventsCap(t *testing.T) {
|
|
| 83 |
+func TestLogEvents(t *testing.T) {
|
|
| 84 | 84 |
e := New() |
| 85 |
- for i := 0; i < eventsLimit+1; i++ {
|
|
| 86 |
- e.Log("action", "id", "from")
|
|
| 87 |
- } |
|
| 88 |
- // let all events go through |
|
| 89 |
- time.Sleep(1 * time.Second) |
|
| 90 | 85 |
|
| 86 |
+ for i := 0; i < eventsLimit+16; i++ {
|
|
| 87 |
+ action := fmt.Sprintf("action_%d", i)
|
|
| 88 |
+ id := fmt.Sprintf("cont_%d", i)
|
|
| 89 |
+ from := fmt.Sprintf("image_%d", i)
|
|
| 90 |
+ e.Log(action, id, from) |
|
| 91 |
+ } |
|
| 92 |
+ time.Sleep(50 * time.Millisecond) |
|
| 91 | 93 |
current, l := e.Subscribe() |
| 92 |
- if len(current) != eventsLimit {
|
|
| 93 |
- t.Fatalf("Must be %d events, got %d", eventsLimit, len(current))
|
|
| 94 |
+ for i := 0; i < 10; i++ {
|
|
| 95 |
+ num := i + eventsLimit + 16 |
|
| 96 |
+ action := fmt.Sprintf("action_%d", num)
|
|
| 97 |
+ id := fmt.Sprintf("cont_%d", num)
|
|
| 98 |
+ from := fmt.Sprintf("image_%d", num)
|
|
| 99 |
+ e.Log(action, id, from) |
|
| 94 | 100 |
} |
| 95 | 101 |
if len(e.events) != eventsLimit {
|
| 96 | 102 |
t.Fatalf("Must be %d events, got %d", eventsLimit, len(e.events))
|
| 97 | 103 |
} |
| 98 | 104 |
|
| 99 |
- for i := 0; i < 10; i++ {
|
|
| 100 |
- e.Log("action", "id", "from")
|
|
| 101 |
- } |
|
| 102 |
- // let all events go through |
|
| 103 |
- time.Sleep(1 * time.Second) |
|
| 104 |
- |
|
| 105 | 105 |
var msgs []*jsonmessage.JSONMessage |
| 106 | 106 |
for len(msgs) < 10 {
|
| 107 |
- select {
|
|
| 108 |
- case m := <-l: |
|
| 109 |
- jm, ok := (m).(*jsonmessage.JSONMessage) |
|
| 110 |
- if !ok {
|
|
| 111 |
- t.Fatalf("Unexpected type %T", m)
|
|
| 112 |
- } |
|
| 113 |
- msgs = append(msgs, jm) |
|
| 114 |
- default: |
|
| 115 |
- t.Fatalf("There is no enough events in channel")
|
|
| 107 |
+ m := <-l |
|
| 108 |
+ jm, ok := (m).(*jsonmessage.JSONMessage) |
|
| 109 |
+ if !ok {
|
|
| 110 |
+ t.Fatalf("Unexpected type %T", m)
|
|
| 116 | 111 |
} |
| 112 |
+ msgs = append(msgs, jm) |
|
| 113 |
+ } |
|
| 114 |
+ if len(current) != eventsLimit {
|
|
| 115 |
+ t.Fatalf("Must be %d events, got %d", eventsLimit, len(current))
|
|
| 116 |
+ } |
|
| 117 |
+ first := current[0] |
|
| 118 |
+ if first.Status != "action_16" {
|
|
| 119 |
+ t.Fatalf("First action is %s, must be action_16", first.Status)
|
|
| 120 |
+ } |
|
| 121 |
+ last := current[len(current)-1] |
|
| 122 |
+ if last.Status != "action_79" {
|
|
| 123 |
+ t.Fatalf("Last action is %s, must be action_79", last.Status)
|
|
| 124 |
+ } |
|
| 125 |
+ |
|
| 126 |
+ firstC := msgs[0] |
|
| 127 |
+ if firstC.Status != "action_80" {
|
|
| 128 |
+ t.Fatalf("First action is %s, must be action_80", firstC.Status)
|
|
| 129 |
+ } |
|
| 130 |
+ lastC := msgs[len(msgs)-1] |
|
| 131 |
+ if lastC.Status != "action_89" {
|
|
| 132 |
+ t.Fatalf("Last action is %s, must be action_89", lastC.Status)
|
|
| 117 | 133 |
} |
| 118 | 134 |
} |