(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestBatch(t *testing.T) { |
| 11 | t.Run("nil", func(t *testing.T) { |
| 12 | var nilChan chan []string |
| 13 | th.ExpectValue(t, Batch(nilChan, 10, 10*time.Second), nil) |
| 14 | }) |
| 15 | |
| 16 | t.Run("fast", func(t *testing.T) { |
| 17 | in := make(chan int) |
| 18 | go func() { |
| 19 | defer close(in) |
| 20 | th.Send(in, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) |
| 21 | }() |
| 22 | |
| 23 | out := Batch(in, 4, 500*time.Millisecond) |
| 24 | |
| 25 | outSlice := th.ToSlice(out) |
| 26 | th.ExpectValue(t, len(outSlice), 3) |
| 27 | th.ExpectSlice(t, outSlice[0], []int{1, 2, 3, 4}) |
| 28 | th.ExpectSlice(t, outSlice[1], []int{5, 6, 7, 8}) |
| 29 | th.ExpectSlice(t, outSlice[2], []int{9, 10}) |
| 30 | }) |
| 31 | |
| 32 | t.Run("slow", func(t *testing.T) { |
| 33 | in := make(chan int) |
| 34 | go func() { |
| 35 | defer close(in) |
| 36 | th.Send(in, 1, 2, 3, 4, 5) |
| 37 | time.Sleep(1 * time.Second) |
| 38 | th.Send(in, 6, 7, 8, 9, 10) |
| 39 | }() |
| 40 | |
| 41 | out := Batch(in, 4, 500*time.Millisecond) |
| 42 | |
| 43 | outSlice := th.ToSlice(out) |
| 44 | th.ExpectValue(t, len(outSlice), 4) |
| 45 | th.ExpectSlice(t, outSlice[0], []int{1, 2, 3, 4}) |
| 46 | th.ExpectSlice(t, outSlice[1], []int{5}) |
| 47 | th.ExpectSlice(t, outSlice[2], []int{6, 7, 8, 9}) |
| 48 | th.ExpectSlice(t, outSlice[3], []int{10}) |
| 49 | }) |
| 50 | |
| 51 | t.Run("slow wo timeout", func(t *testing.T) { |
| 52 | in := make(chan int) |
| 53 | go func() { |
| 54 | defer close(in) |
| 55 | th.Send(in, 1, 2, 3, 4, 5) |
| 56 | time.Sleep(1 * time.Second) |
| 57 | th.Send(in, 6, 7, 8, 9, 10) |
| 58 | }() |
| 59 | |
| 60 | out := Batch(in, 4, -1) |
| 61 | |
| 62 | outSlice := th.ToSlice(out) |
| 63 | th.ExpectValue(t, len(outSlice), 3) |
| 64 | th.ExpectSlice(t, outSlice[0], []int{1, 2, 3, 4}) |
| 65 | th.ExpectSlice(t, outSlice[1], []int{5, 6, 7, 8}) |
| 66 | th.ExpectSlice(t, outSlice[2], []int{9, 10}) |
| 67 | }) |
nothing calls this directly
no test coverage detected