(t *testing.T)
| 155 | } |
| 156 | |
| 157 | func TestPopTask(t *testing.T) { |
| 158 | a, ctx := test.New(t) |
| 159 | |
| 160 | cl, flush := test.NewRedis(ctx, "redis_test") |
| 161 | defer flush() |
| 162 | defer cl.Close() |
| 163 | |
| 164 | const ( |
| 165 | testGroup = "testGroup" |
| 166 | |
| 167 | testKey1 = "testKey1" |
| 168 | testKey2 = "testKey2" |
| 169 | ) |
| 170 | |
| 171 | assertPop := func(ctx context.Context, inputKey, expectedPayload string, expectedStartAt time.Time) bool { |
| 172 | t, a := test.MustNewTFromContext(ctx) |
| 173 | t.Helper() |
| 174 | |
| 175 | var called bool |
| 176 | errCh := make(chan error, 1) |
| 177 | go func() { |
| 178 | errCh <- PopTask( |
| 179 | ctx, |
| 180 | cl.Client, |
| 181 | testGroup, |
| 182 | "testID", |
| 183 | func(p redis.Pipeliner, payload string, startAt time.Time) error { |
| 184 | p.Ping(ctx) |
| 185 | if !test.AllTrue( |
| 186 | a.So(called, should.BeFalse), |
| 187 | a.So(payload, should.Equal, expectedPayload), |
| 188 | a.So(startAt, should.Resemble, expectedStartAt), |
| 189 | ) { |
| 190 | t.Errorf( |
| 191 | "PopTask assertion failed for task with expected payload %s and expected starting time of %s", //nolint:lll |
| 192 | expectedPayload, |
| 193 | expectedStartAt, |
| 194 | ) |
| 195 | } |
| 196 | called = true |
| 197 | return nil |
| 198 | }, |
| 199 | inputKey, |
| 200 | testStreamBlockLimit(), |
| 201 | ) |
| 202 | }() |
| 203 | |
| 204 | select { |
| 205 | case <-ctx.Done(): |
| 206 | t.Error("Timed out while waiting for Pop callback to be called") |
| 207 | return false |
| 208 | |
| 209 | case err := <-errCh: |
| 210 | if !a.So(err, should.BeNil) { |
| 211 | t.Errorf("PopTask failed with: %s", test.FormatError(err)) |
| 212 | } |
| 213 | return a.So(called, should.BeTrue) && !a.Failed() |
| 214 | } |
nothing calls this directly
no test coverage detected