(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestSimpleQueue(t *testing.T) { |
| 10 | ctx, cancel := context.WithCancel(context.Background()) |
| 11 | defer cancel() |
| 12 | |
| 13 | // set up a small queue with very small buffers so we can |
| 14 | // watch it shed load, then send a bunch of messages to the |
| 15 | // queue, most of which we'll watch it drop. |
| 16 | sq := newSimplePriorityQueue(ctx, 1, nil) |
| 17 | for i := 0; i < 100; i++ { |
| 18 | sq.enqueue() <- Envelope{From: "merlin"} |
| 19 | } |
| 20 | |
| 21 | seen := 0 |
| 22 | |
| 23 | RETRY: |
| 24 | for seen <= 2 { |
| 25 | select { |
| 26 | case e := <-sq.dequeue(): |
| 27 | if e.From != "merlin" { |
| 28 | continue |
| 29 | } |
| 30 | seen++ |
| 31 | case <-time.After(10 * time.Millisecond): |
| 32 | break RETRY |
| 33 | } |
| 34 | } |
| 35 | // if we don't see any messages, then it's just broken. |
| 36 | if seen == 0 { |
| 37 | t.Errorf("seen %d messages, should have seen more than one", seen) |
| 38 | } |
| 39 | // ensure that load shedding happens: there can be at most 3 |
| 40 | // messages that we get out of this, one that was buffered |
| 41 | // plus 2 that were under the cap, everything else gets |
| 42 | // dropped. |
| 43 | if seen > 3 { |
| 44 | t.Errorf("saw %d messages, should have seen 5 or fewer", seen) |
| 45 | } |
| 46 | |
| 47 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…