MCPcopy
hub / github.com/grafana/tempo / TestWorker

Function TestWorker

modules/backendworker/backendworker_test.go:37–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35var tenant = "test-tenant"
36
37func TestWorker(t *testing.T) {
38 limitCfg := overrides.Config{}
39 limitCfg.RegisterFlagsAndApplyDefaults(&flag.FlagSet{})
40
41 ctx, cancel := context.WithCancel(context.Background())
42
43 workerCfg, schedulerClientCfg, overridesSvc, scheduler, store := setupDependencies(ctx, t, limitCfg)
44
45 defer func() {
46 cancel()
47 // Explicitly stop the store to avoid race condition on test fixture shutdown
48 store.StopAsync()
49 _ = store.AwaitTerminated(context.Background())
50 }()
51
52 w, err := New(workerCfg, schedulerClientCfg, store, overridesSvc, prometheus.DefaultRegisterer)
53 require.NoError(t, err)
54 require.NotNil(t, w)
55
56 w.backendScheduler = scheduler
57
58 err = w.processJobs(ctx)
59 require.Error(t, err, "no jobs found")
60
61 w.backendScheduler = &mockScheduler{
62 next: nextFuncWithJob(store, tenant),
63 updateJob: updateJobNoop,
64 }
65
66 err = w.processJobs(ctx)
67 require.NoError(t, err)
68
69 err = services.StopAndAwaitTerminated(ctx, w)
70 require.NoError(t, err)
71}
72
73func setupDependencies(ctx context.Context, t *testing.T, limits overrides.Config) (Config, backendscheduler_client.Config, overrides.Service, *mockScheduler, storage.Store) {
74 t.Helper()

Callers

nothing calls this directly

Calls 6

nextFuncWithJobFunction · 0.85
processJobsMethod · 0.80
setupDependenciesFunction · 0.70
NewFunction · 0.70
ErrorMethod · 0.65

Tested by

no test coverage detected