Skip to content

Agent Mesh

node: stop the background loops of nodes started in tests

Antonio Ojea947622a66dd3
diff --git a/internal/node/enroll_test.go b/internal/node/enroll_test.go
index 504f2b48..05bdf62f 100644
--- a/internal/node/enroll_test.go
+++ b/internal/node/enroll_test.go
@@ -587,10 +587,12 @@ func TestEnroll_InvalidControlPlanePublicKeySize(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- ctx := context.Background()
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
if err := node.Start(ctx); err != nil {
t.Fatal(err)
}
+ defer func() { _ = node.Host.Close() }()
// 3. Call enroll which should fail due to public key validation
err = node.Enroll(context.Background(), srv.URL, "dummy-jwt")
diff --git a/internal/node/static_service_test.go b/internal/node/static_service_test.go
index 3166afae..18876d99 100644
--- a/internal/node/static_service_test.go
+++ b/internal/node/static_service_test.go
@@ -196,7 +196,8 @@ func TestStaticServiceRegistrationRequiresConnection(t *testing.T) {
t.Fatalf("failed to create node: %v", err)
}
node.BiscuitTimeout = 10 * time.Second
- ctx := context.Background()
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
if err := node.Start(ctx); err != nil {
t.Fatalf("failed to start node: %v", err)
}
@@ -282,7 +283,8 @@ func TestStaticServiceRegistrationCommandFailure(t *testing.T) {
t.Fatalf("failed to create node: %v", err)
}
node.BiscuitTimeout = 10 * time.Second
- ctx := context.Background()
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
if err := node.Start(ctx); err != nil {
t.Fatalf("failed to start node: %v", err)
}