Skip to content

Commit

Permalink
fix flakey test
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbailey committed Oct 8, 2020
1 parent df3ca7f commit 364b23e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions nomad/event_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ func TestEventStream_StreamErr(t *testing.T) {
require.NoError(t, err)

node := mock.Node()
publisher.Publish(&structs.Events{uint64(1), []structs.Event{{Topic: "test", Payload: node}}})

// send req
encoder := codec.NewEncoder(p1, structs.MsgpackHandle)
require.Nil(t, encoder.Encode(req))

// stop the publisher to force an error on subscription side
s1.State().StopEventPublisher()
// publish some events
publisher.Publish(&structs.Events{Index: uint64(1), Events: []structs.Event{{Topic: "test", Payload: node}}})
publisher.Publish(&structs.Events{Index: uint64(2), Events: []structs.Event{{Topic: "test", Payload: node}}})

timeout := time.After(5 * time.Second)
OUTER:
Expand All @@ -178,8 +178,10 @@ OUTER:
case err := <-errCh:
t.Fatal(err)
case msg := <-streamMsg:
// close the publishers subscriptions forcing an error
// after an initial event is received
publisher.CloseAll()
if msg.Error == nil {
// race between error and receiving an event
// continue trying for error
continue
}
Expand Down
4 changes: 4 additions & 0 deletions nomad/stream/event_publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func (e *EventPublisher) Subscribe(req *SubscribeRequest) (*Subscription, error)
return sub, nil
}

func (e *EventPublisher) CloseAll() {
e.subscriptions.closeAll()
}

func (e *EventPublisher) handleUpdates(ctx context.Context) {
for {
select {
Expand Down

0 comments on commit 364b23e

Please sign in to comment.