|
5 | 5 | "errors" |
6 | 6 | "fmt" |
7 | 7 | "sync/atomic" |
| 8 | + "testing" |
| 9 | + "testing/synctest" |
8 | 10 | "time" |
9 | 11 |
|
10 | 12 | . "github.com/onsi/ginkgo/v2" |
@@ -110,30 +112,6 @@ var _ = Describe("runnables", func() { |
110 | 112 | Expect(r.Others.startQueue).To(BeEmpty()) |
111 | 113 | }) |
112 | 114 |
|
113 | | - It("should execute the Warmup function when Warmup group is started", func(ctx SpecContext) { |
114 | | - var warmupExecuted atomic.Bool |
115 | | - |
116 | | - warmupRunnable := newWarmupRunnableFunc( |
117 | | - func(c context.Context) error { |
118 | | - <-c.Done() |
119 | | - return nil |
120 | | - }, |
121 | | - func(c context.Context) error { |
122 | | - warmupExecuted.Store(true) |
123 | | - return nil |
124 | | - }, |
125 | | - ) |
126 | | - |
127 | | - r := newRunnables(defaultBaseContext, errCh) |
128 | | - Expect(r.Add(warmupRunnable)).To(Succeed()) |
129 | | - |
130 | | - // Start the Warmup group |
131 | | - Expect(r.Warmup.Start(ctx)).To(Succeed()) |
132 | | - |
133 | | - // Verify warmup function was called |
134 | | - Expect(warmupExecuted.Load()).To(BeTrue()) |
135 | | - }) |
136 | | - |
137 | 115 | It("should propagate errors from Warmup function to error channel", func(ctx SpecContext) { |
138 | 116 | expectedErr := fmt.Errorf("expected warmup error") |
139 | 117 |
|
@@ -384,3 +362,33 @@ func newLeaderElectionAndWarmupRunnable( |
384 | 362 | func (r leaderElectionAndWarmupRunnable) NeedLeaderElection() bool { |
385 | 363 | return r.needLeaderElection |
386 | 364 | } |
| 365 | + |
| 366 | +func TestWarmupFunctionIsExecutedWhenWarmupGroupIsStarted(t *testing.T) { |
| 367 | + t.Parallel() |
| 368 | + synctest.Test(t, func(t *testing.T) { |
| 369 | + g := NewWithT(t) |
| 370 | + var warmupExecuted atomic.Bool |
| 371 | + |
| 372 | + warmupRunnable := newWarmupRunnableFunc( |
| 373 | + func(c context.Context) error { |
| 374 | + <-c.Done() |
| 375 | + return nil |
| 376 | + }, |
| 377 | + func(c context.Context) error { |
| 378 | + warmupExecuted.Store(true) |
| 379 | + return nil |
| 380 | + }, |
| 381 | + ) |
| 382 | + |
| 383 | + r := newRunnables(defaultBaseContext, make(chan error)) |
| 384 | + g.Expect(r.Add(warmupRunnable)).To(Succeed()) |
| 385 | + |
| 386 | + // Start the Warmup group |
| 387 | + g.Expect(r.Warmup.Start(t.Context())).To(Succeed()) |
| 388 | + synctest.Wait() |
| 389 | + |
| 390 | + // Verify warmup function was called |
| 391 | + g.Expect(warmupExecuted.Load()).To(BeTrue()) |
| 392 | + r.Warmup.StopAndWait(t.Context()) |
| 393 | + }) |
| 394 | +} |
0 commit comments