plugin: fix flaky scheduler lock test (#10432)

plugin: stop the scheduler lock test racing its own background loops

TestRunLaneSchedulerIterationLockBehavior constructed the plugin with a
cluster-context provider, which makes New start a background scheduler
loop per lane. Those loops call runLaneSchedulerIteration on the same
lane the test then drives by hand, so a loop could consume the due job —
running detection and pushing the next-detection time forward — before
the manual call observed the lock. The Default case then saw the lock
acquired zero times and failed intermittently.

Construct without the provider so no loops start, and set the provider
afterward so the manual iteration can still detect. This is the pattern
scheduler_status_test.go already uses for the same reason.

Reproduced under -race -count=100 -p 4 before, green after.

Claude-Session: https://claude.ai/code/session_01Ks16jnt4S7gdDk8cheQ3xu
This commit is contained in:
Chris Lu
2026-07-24 17:51:33 -07:00
committed by GitHub
parent 19ce7c0b6f
commit cba2e5150c
+9 -6
View File
@@ -633,16 +633,19 @@ func TestRunLaneSchedulerIterationLockBehavior(t *testing.T) {
t.Parallel()
lm := &trackingLockManager{}
pluginSvc, err := New(Options{
LockManager: lm,
ClusterContextProvider: func(context.Context) (*plugin_pb.ClusterContext, error) {
return &plugin_pb.ClusterContext{}, nil
},
})
// Construct without a cluster-context provider so the background
// lane loops do not start: they call runLaneSchedulerIteration on
// the same lane and would race this test's own manual call,
// consuming the due job before it observes the lock. The provider
// is set afterward so the manual iteration can still detect.
pluginSvc, err := New(Options{LockManager: lm})
if err != nil {
t.Fatalf("New: %v", err)
}
defer pluginSvc.Shutdown()
pluginSvc.clusterContextProvider = func(context.Context) (*plugin_pb.ClusterContext, error) {
return &plugin_pb.ClusterContext{}, nil
}
// Register a detectable worker for the job type.
pluginSvc.registry.UpsertFromHello(&plugin_pb.WorkerHello{