TestRedisQueue tests that the redis queue works as expected it's implemented in one method to test possible interactions between different tests
(t *testing.T)
| 87 | // TestRedisQueue tests that the redis queue works as expected |
| 88 | // it's implemented in one method to test possible interactions between different tests |
| 89 | func TestRedisQueue(t *testing.T) { |
| 90 | ctx := context.Background() |
| 91 | r := newQueueRunner("test_queue") |
| 92 | worker := newTestWorker() |
| 93 | |
| 94 | // |
| 95 | |
| 96 | // test that queue can be cancelled |
| 97 | t.Run("empty queue cancel", func(t *testing.T) { |
| 98 | r.startProcessLoop(ctx, []ProcessFunc{worker.processOk}) |
| 99 | |
| 100 | // wait so code gets to the blocking pop opearation |
| 101 | time.Sleep(10 * time.Millisecond) |
| 102 | |
| 103 | r.stopProcessLoop() |
| 104 | }) |
| 105 | |
| 106 | // test that normal processing works |
| 107 | t.Run("normal processing", func(t *testing.T) { |
| 108 | r.startProcessLoop(ctx, []ProcessFunc{worker.processOk}) |
| 109 | |
| 110 | err := r.queue.UpdateBlock(1) |
| 111 | require.NoError(t, err) |
| 112 | |
| 113 | err = r.queue.Push(context.Background(), []byte("test"), false, 2, 2) |
| 114 | require.NoError(t, err) |
| 115 | |
| 116 | require.Equal(t, "test", string(worker.nextProcessed(processTimeout))) |
| 117 | |
| 118 | require.Nil(t, worker.nextProcessed(processTimeout)) |
| 119 | |
| 120 | r.stopProcessLoop() |
| 121 | }) |
| 122 | |
| 123 | // test multiple workers |
| 124 | t.Run("multiple workers", func(t *testing.T) { |
| 125 | workers := MultipleWorkers(worker.processOk, 10, rate.Inf, 1) |
| 126 | r.startProcessLoop(ctx, workers) |
| 127 | |
| 128 | err := r.queue.UpdateBlock(1) |
| 129 | require.NoError(t, err) |
| 130 | |
| 131 | for i := 0; i < 10; i++ { |
| 132 | err = r.queue.Push(ctx, []byte("test-multiple"), false, 2, 2) |
| 133 | require.NoError(t, err) |
| 134 | } |
| 135 | |
| 136 | for i := 0; i < 10; i++ { |
| 137 | require.Equal(t, "test-multiple", string(worker.nextProcessed(processTimeout))) |
| 138 | } |
| 139 | |
| 140 | require.Nil(t, worker.nextProcessed(processTimeout)) |
| 141 | r.stopProcessLoop() |
| 142 | }) |
| 143 | |
| 144 | // test that stale items are not processed |
| 145 | t.Run("test queue cleanup", func(t *testing.T) { |
| 146 | err := r.queue.Push(context.Background(), []byte("test-stale"), false, 2, 2) |
nothing calls this directly
no test coverage detected