Skip to content

Commit 0b03f92

Browse files
committed
test: don't leak goroutine
1 parent 8ae8144 commit 0b03f92

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

nomad/node_endpoint_test.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -559,14 +559,19 @@ func TestClientEndpoint_UpdateStatus_Reconnect(t *testing.T) {
559559
ticker.Stop()
560560
return
561561
case <-ticker.C:
562+
if t.Failed() {
563+
return
564+
}
565+
562566
req := &structs.NodeUpdateStatusRequest{
563567
NodeID: node.ID,
564568
Status: structs.NodeStatusReady,
565569
WriteRequest: structs.WriteRequest{Region: "global"},
566570
}
567571
var resp structs.NodeUpdateResponse
568-
err := msgpackrpc.CallWithCodec(codec, "Node.UpdateStatus", req, &resp)
569-
must.NoError(t, err)
572+
// Ignore errors since an unexpected failed hearbeat will cause
573+
// the test conditions to fail.
574+
msgpackrpc.CallWithCodec(codec, "Node.UpdateStatus", req, &resp)
570575
}
571576
}
572577
}
@@ -689,6 +694,10 @@ func TestClientEndpoint_UpdateStatus_Reconnect(t *testing.T) {
689694

690695
// Wait for the client to be ready.
691696
testutil.WaitForClientStatus(t, s.RPC, node.ID, "global", structs.NodeStatusReady)
697+
698+
// Cleanup heartbeat goroutine before exiting.
699+
close(stopHeartbeat)
700+
testutil.WaitForClientStatus(t, s.RPC, node.ID, "global", structs.NodeStatusDisconnected)
692701
}
693702

694703
func TestClientEndpoint_UpdateStatus_HeartbeatRecovery(t *testing.T) {

0 commit comments

Comments
 (0)