Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions pkg/manager/runnable_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"fmt"
"sync/atomic"
"testing"
"testing/synctest"
"time"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -110,30 +112,6 @@ var _ = Describe("runnables", func() {
Expect(r.Others.startQueue).To(BeEmpty())
})

It("should execute the Warmup function when Warmup group is started", func(ctx SpecContext) {
var warmupExecuted atomic.Bool

warmupRunnable := newWarmupRunnableFunc(
func(c context.Context) error {
<-c.Done()
return nil
},
func(c context.Context) error {
warmupExecuted.Store(true)
return nil
},
)

r := newRunnables(defaultBaseContext, errCh)
Expect(r.Add(warmupRunnable)).To(Succeed())

// Start the Warmup group
Expect(r.Warmup.Start(ctx)).To(Succeed())

// Verify warmup function was called
Expect(warmupExecuted.Load()).To(BeTrue())
})

It("should propagate errors from Warmup function to error channel", func(ctx SpecContext) {
expectedErr := fmt.Errorf("expected warmup error")

Expand Down Expand Up @@ -384,3 +362,33 @@ func newLeaderElectionAndWarmupRunnable(
func (r leaderElectionAndWarmupRunnable) NeedLeaderElection() bool {
return r.needLeaderElection
}

func TestWarmupFunctionIsExecutedWhenWarmupGroupIsStarted(t *testing.T) {
t.Parallel()
synctest.Test(t, func(t *testing.T) {
g := NewWithT(t)
var warmupExecuted atomic.Bool

warmupRunnable := newWarmupRunnableFunc(
func(c context.Context) error {
<-c.Done()
return nil
},
func(c context.Context) error {
warmupExecuted.Store(true)
return nil
},
)

r := newRunnables(defaultBaseContext, make(chan error))
g.Expect(r.Add(warmupRunnable)).To(Succeed())

// Start the Warmup group
g.Expect(r.Warmup.Start(t.Context())).To(Succeed())
synctest.Wait()

// Verify warmup function was called
g.Expect(warmupExecuted.Load()).To(BeTrue())
r.Warmup.StopAndWait(t.Context())
})
}