MCPcopy
hub / github.com/flyteorg/flyte / TestQueueBuildUp

Function TestQueueBuildUp

flytestdlib/cache/in_memory_auto_refresh_test.go:279–321  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

277}
278
279func 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
323func TestInProcessing(t *testing.T) {
324 syncer := &panickingSyncer{}

Callers

nothing calls this directly

Calls 11

IncMethod · 0.95
StartMethod · 0.95
GetOrCreateMethod · 0.95
LoadMethod · 0.95
NewInt32Function · 0.92
NewTestScopeFunction · 0.92
NewInMemoryAutoRefreshFunction · 0.85
WithClockFunction · 0.85
ErrorfMethod · 0.80
LenMethod · 0.65
GetIDMethod · 0.65

Tested by

no test coverage detected