MCPcopy Create free account
hub / github.com/cairoeth/preconfirmations / TestRedisQueue

Function TestRedisQueue

preconf-share/simqueue/queue_test.go:89–292  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

87// TestRedisQueue tests that the redis queue works as expected
88// it's implemented in one method to test possible interactions between different tests
89func 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)

Callers

nothing calls this directly

Calls 12

newQueueRunnerFunction · 0.85
newTestWorkerFunction · 0.85
MultipleWorkersFunction · 0.85
testQueuePushFunction · 0.85
testQueueReschedFunction · 0.85
startProcessLoopMethod · 0.80
stopProcessLoopMethod · 0.80
nextProcessedMethod · 0.80
UpdateBlockMethod · 0.65
PushMethod · 0.65

Tested by

no test coverage detected