(t *testing.T)
| 173 | } |
| 174 | |
| 175 | func TestWorker_LimitsToNRows(t *testing.T) { |
| 176 | t.Parallel() |
| 177 | ctx := testutil.Context(t, testutil.WaitShort) |
| 178 | |
| 179 | var capturedLimit atomic.Int32 |
| 180 | var upsertCount atomic.Int32 |
| 181 | ownerID := uuid.New() |
| 182 | const numRows = 5 |
| 183 | tickDone := make(chan struct{}) |
| 184 | |
| 185 | rows := make([]database.AcquireStaleChatDiffStatusesRow, numRows) |
| 186 | for i := range rows { |
| 187 | rows[i] = makeAcquiredRowWithBranch(uuid.New(), ownerID, "feature") |
| 188 | } |
| 189 | |
| 190 | ctrl := gomock.NewController(t) |
| 191 | store := dbmock.NewMockStore(ctrl) |
| 192 | |
| 193 | store.EXPECT().AcquireStaleChatDiffStatuses(gomock.Any(), gomock.Any()). |
| 194 | DoAndReturn(func(_ context.Context, limitVal int32) ([]database.AcquireStaleChatDiffStatusesRow, error) { |
| 195 | capturedLimit.Store(limitVal) |
| 196 | return rows, nil |
| 197 | }) |
| 198 | store.EXPECT().UpsertChatDiffStatus(gomock.Any(), gomock.Any()). |
| 199 | DoAndReturn(func(_ context.Context, arg database.UpsertChatDiffStatusParams) (database.ChatDiffStatus, error) { |
| 200 | upsertCount.Add(1) |
| 201 | return database.ChatDiffStatus{ChatID: arg.ChatID}, nil |
| 202 | }).Times(numRows) |
| 203 | |
| 204 | pub := func(_ context.Context, _ uuid.UUID) error { |
| 205 | if upsertCount.Load() == numRows { |
| 206 | close(tickDone) |
| 207 | } |
| 208 | return nil |
| 209 | } |
| 210 | |
| 211 | mClock := quartz.NewMock(t) |
| 212 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) |
| 213 | refresher := newTestRefresher(t, mClock) |
| 214 | worker := gitsync.NewWorker(store, refresher, pub, mClock, logger) |
| 215 | |
| 216 | tickOnce(ctx, t, mClock, worker, tickDone) |
| 217 | |
| 218 | // The default batch size is 50. |
| 219 | assert.Equal(t, int32(50), capturedLimit.Load()) |
| 220 | assert.Equal(t, int32(numRows), upsertCount.Load()) |
| 221 | } |
| 222 | |
| 223 | func TestWorker_NoPR_RecentMarkStale_BacksOffShort(t *testing.T) { |
| 224 | t.Parallel() |
nothing calls this directly
no test coverage detected