(t *testing.T)
| 1174 | } |
| 1175 | |
| 1176 | func TestWorker_NoTokenBackoff(t *testing.T) { |
| 1177 | t.Parallel() |
| 1178 | ctx := testutil.Context(t, testutil.WaitShort) |
| 1179 | |
| 1180 | chatID := uuid.New() |
| 1181 | ownerID := uuid.New() |
| 1182 | |
| 1183 | var mu sync.Mutex |
| 1184 | var backoffArgs []database.BackoffChatDiffStatusParams |
| 1185 | tickDone := make(chan struct{}) |
| 1186 | |
| 1187 | mClock := quartz.NewMock(t) |
| 1188 | |
| 1189 | ctrl := gomock.NewController(t) |
| 1190 | store := dbmock.NewMockStore(ctrl) |
| 1191 | |
| 1192 | store.EXPECT().AcquireStaleChatDiffStatuses(gomock.Any(), gomock.Any()). |
| 1193 | Return([]database.AcquireStaleChatDiffStatusesRow{ |
| 1194 | makeAcquiredRowWithBranch(chatID, ownerID, "feature"), |
| 1195 | }, nil) |
| 1196 | store.EXPECT().BackoffChatDiffStatus(gomock.Any(), gomock.Any()). |
| 1197 | DoAndReturn(func(_ context.Context, arg database.BackoffChatDiffStatusParams) error { |
| 1198 | mu.Lock() |
| 1199 | backoffArgs = append(backoffArgs, arg) |
| 1200 | mu.Unlock() |
| 1201 | close(tickDone) |
| 1202 | return nil |
| 1203 | }) |
| 1204 | |
| 1205 | // Token resolver returns empty token → ErrNoTokenAvailable. |
| 1206 | // Provider methods should never be called. |
| 1207 | prov := &mockProvider{} |
| 1208 | providers := func(context.Context, string) gitprovider.Provider { return prov } |
| 1209 | tokens := func(context.Context, uuid.UUID, string) (*string, error) { |
| 1210 | return ptr.Ref(""), nil |
| 1211 | } |
| 1212 | |
| 1213 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) |
| 1214 | refresher := gitsync.NewRefresher(providers, tokens, logger, mClock) |
| 1215 | worker := gitsync.NewWorker(store, refresher, nil, mClock, logger) |
| 1216 | |
| 1217 | tickOnce(ctx, t, mClock, worker, tickDone) |
| 1218 | |
| 1219 | mu.Lock() |
| 1220 | defer mu.Unlock() |
| 1221 | require.Len(t, backoffArgs, 1) |
| 1222 | assert.Equal(t, chatID, backoffArgs[0].ChatID) |
| 1223 | |
| 1224 | // The backoff should use NoTokenBackoff (10min), not |
| 1225 | // DiffStatusTTL (2min). |
| 1226 | expectedStaleAt := mClock.Now().UTC().Add(gitsync.NoTokenBackoff) |
| 1227 | assert.WithinDuration(t, expectedStaleAt, backoffArgs[0].StaleAt, time.Second) |
| 1228 | } |
nothing calls this directly
no test coverage detected