Skip to content

Commit

Permalink
Actually use the mock Clock so we do not wait in test
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Apr 10, 2024
1 parent ff7828f commit b9a6953
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/node/manager/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type EventEmitterSuite struct {
suite.Suite
ctrl *gomock.Controller
ctx context.Context
clock clock.Clock
clock *clock.Mock
}

func TestEventEmitterSuite(t *testing.T) {
Expand Down Expand Up @@ -79,19 +79,23 @@ func (s *EventEmitterSuite) TestEmitEventWithNoCallbacks() {
}

func (s *EventEmitterSuite) TestEmitWithSlowCallback() {
e := manager.NewNodeEventEmitter()
e := manager.NewNodeEventEmitter(manager.WithClock(s.clock))
s.NotNil(e)

e.RegisterHandler(testSleepyHandler{s})
e.RegisterHandler(testSleepyHandler{s.clock})

go func() {
s.clock.Add(10 * time.Second)
}()

err := e.EmitEvent(s.ctx, models.NodeInfo{}, manager.NodeEventRejected)
s.Error(err)
}

type testSleepyHandler struct {
s *EventEmitterSuite
c *clock.Mock
}

func (t testSleepyHandler) HandleNodeEvent(ctx context.Context, info models.NodeInfo, event manager.NodeEvent) {
t.s.clock.Sleep(2 * time.Second)
t.c.Sleep(2 * time.Second)
}

0 comments on commit b9a6953

Please sign in to comment.