(t *testing.T)
| 403 | } |
| 404 | |
| 405 | func TestWorker_RefresherError_BacksOffRow(t *testing.T) { |
| 406 | t.Parallel() |
| 407 | ctx := testutil.Context(t, testutil.WaitShort) |
| 408 | |
| 409 | chat1 := uuid.New() |
| 410 | chat2 := uuid.New() |
| 411 | ownerID := uuid.New() |
| 412 | |
| 413 | var upsertCount atomic.Int32 |
| 414 | var publishCount atomic.Int32 |
| 415 | var backoffCount atomic.Int32 |
| 416 | var mu sync.Mutex |
| 417 | var backoffArgs []database.BackoffChatDiffStatusParams |
| 418 | tickDone := make(chan struct{}) |
| 419 | var closeOnce sync.Once |
| 420 | |
| 421 | // Two rows processed: one fails (backoff), one succeeds |
| 422 | // (upsert+publish). Both must finish before we close tickDone. |
| 423 | var terminalOps atomic.Int32 |
| 424 | signalIfDone := func() { |
| 425 | if terminalOps.Add(1) == 2 { |
| 426 | closeOnce.Do(func() { close(tickDone) }) |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | mClock := quartz.NewMock(t) |
| 431 | |
| 432 | ctrl := gomock.NewController(t) |
| 433 | store := dbmock.NewMockStore(ctrl) |
| 434 | |
| 435 | store.EXPECT().AcquireStaleChatDiffStatuses(gomock.Any(), gomock.Any()). |
| 436 | Return([]database.AcquireStaleChatDiffStatusesRow{ |
| 437 | makeAcquiredRowWithBranch(chat1, ownerID, "fail-branch"), |
| 438 | makeAcquiredRowWithBranch(chat2, ownerID, "success-branch"), |
| 439 | }, nil) |
| 440 | store.EXPECT().BackoffChatDiffStatus(gomock.Any(), gomock.Any()). |
| 441 | DoAndReturn(func(_ context.Context, arg database.BackoffChatDiffStatusParams) error { |
| 442 | backoffCount.Add(1) |
| 443 | mu.Lock() |
| 444 | backoffArgs = append(backoffArgs, arg) |
| 445 | mu.Unlock() |
| 446 | signalIfDone() |
| 447 | return nil |
| 448 | }) |
| 449 | store.EXPECT().UpsertChatDiffStatus(gomock.Any(), gomock.Any()). |
| 450 | DoAndReturn(func(_ context.Context, arg database.UpsertChatDiffStatusParams) (database.ChatDiffStatus, error) { |
| 451 | upsertCount.Add(1) |
| 452 | return database.ChatDiffStatus{ChatID: arg.ChatID}, nil |
| 453 | }) |
| 454 | |
| 455 | pub := func(_ context.Context, _ uuid.UUID) error { |
| 456 | // Only the successful row publishes. |
| 457 | publishCount.Add(1) |
| 458 | signalIfDone() |
| 459 | return nil |
| 460 | } |
| 461 | |
| 462 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) |
nothing calls this directly
no test coverage detected