(t *testing.T)
| 277 | } |
| 278 | |
| 279 | func TestQueueBuildUp(t *testing.T) { |
| 280 | testResyncPeriod := time.Hour |
| 281 | rateLimiter := workqueue.DefaultTypedControllerRateLimiter[*Batch]() |
| 282 | fakeClock := testingclock.NewFakeClock(time.Now()) |
| 283 | |
| 284 | syncCount := atomic.NewInt32(0) |
| 285 | m := sync.Map{} |
| 286 | alwaysFailing := func(ctx context.Context, batch Batch) ( |
| 287 | updatedBatch []ItemSyncResponse, err error) { |
| 288 | assert.Len(t, batch, 1) |
| 289 | _, existing := m.LoadOrStore(batch[0].GetID(), 0) |
| 290 | assert.False(t, existing, "Saw %v before", batch[0].GetID()) |
| 291 | if existing { |
| 292 | t.FailNow() |
| 293 | } |
| 294 | |
| 295 | syncCount.Inc() |
| 296 | return nil, fmt.Errorf("expected error") |
| 297 | } |
| 298 | |
| 299 | size := uint(100) |
| 300 | cache, err := NewInMemoryAutoRefresh("fake2", alwaysFailing, rateLimiter, testResyncPeriod, 10, size, promutils.NewTestScope(), WithClock(fakeClock)) |
| 301 | assert.NoError(t, err) |
| 302 | |
| 303 | ctx, cancel := context.WithCancel(context.Background()) |
| 304 | assert.NoError(t, cache.Start(ctx)) |
| 305 | defer cancel() |
| 306 | |
| 307 | for i := uint(0); i < size; i++ { |
| 308 | // #nosec G115 |
| 309 | _, err := cache.GetOrCreate(strconv.Itoa(int(i)), fakeCacheItem{val: 3}) |
| 310 | assert.NoError(t, err) |
| 311 | } |
| 312 | |
| 313 | // wait for all workers to run |
| 314 | assert.Eventually(t, func() bool { |
| 315 | // trigger a sync and unlock the work queue |
| 316 | fakeClock.Step(time.Millisecond) |
| 317 | |
| 318 | return syncCount.Load() == int32(size) // #nosec G115 |
| 319 | |
| 320 | }, 5*time.Second, time.Millisecond) |
| 321 | } |
| 322 | |
| 323 | func TestInProcessing(t *testing.T) { |
| 324 | syncer := &panickingSyncer{} |
nothing calls this directly
no test coverage detected