MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestForEach

Function TestForEach

pkg/util/concurrency/runner_test.go:75–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

73}
74
75func TestForEach(t *testing.T) {
76 var (
77 ctx = context.Background()
78
79 // Keep track of processed jobs.
80 processedMx sync.Mutex
81 processed []string
82 )
83
84 jobs := []string{"a", "b", "c"}
85
86 err := ForEach(ctx, CreateJobsFromStrings(jobs), 2, func(ctx context.Context, job any) error {
87 processedMx.Lock()
88 defer processedMx.Unlock()
89 processed = append(processed, job.(string))
90 return nil
91 })
92
93 require.NoError(t, err)
94 assert.ElementsMatch(t, jobs, processed)
95}
96
97func TestForEach_ShouldBreakOnFirstError_ContextCancellationHandled(t *testing.T) {
98 var (

Callers

nothing calls this directly

Calls 2

ForEachFunction · 0.85
CreateJobsFromStringsFunction · 0.85

Tested by

no test coverage detected