From 7214be78f76691c604e47a4cb67933631a9695a1 Mon Sep 17 00:00:00 2001 From: Matthew Sykes Date: Mon, 9 Nov 2020 17:50:53 -0500 Subject: [PATCH] Prevent race that occurs after test timeout The `instance` variable used in the suite was referenced by a transient go routine used in the test after the test failed due to a timeout. Instead of dereferencing the instance to acquire the session, pass the session directly to the go routine. Signed-off-by: Matthew Sykes --- core/container/externalbuilder/instance_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/container/externalbuilder/instance_test.go b/core/container/externalbuilder/instance_test.go index c2766e29716..eb9e9f517ae 100644 --- a/core/container/externalbuilder/instance_test.go +++ b/core/container/externalbuilder/instance_test.go @@ -284,7 +284,7 @@ var _ = Describe("Instance", func() { Expect(instance.Session).NotTo(BeNil()) errCh := make(chan error) - go func() { errCh <- instance.Session.Wait() }() + go func(sess *externalbuilder.Session) { errCh <- sess.Wait() }(instance.Session) Eventually(errCh).Should(Receive(BeNil())) }) }) @@ -298,7 +298,7 @@ var _ = Describe("Instance", func() { instance.TermTimeout = time.Minute errCh := make(chan error) - go func() { errCh <- instance.Session.Wait() }() + go func() { errCh <- sess.Wait() }() Consistently(errCh).ShouldNot(Receive()) err = instance.Stop() @@ -316,7 +316,7 @@ var _ = Describe("Instance", func() { instance.TermTimeout = time.Second errCh := make(chan error) - go func() { errCh <- instance.Session.Wait() }() + go func() { errCh <- sess.Wait() }() Consistently(errCh).ShouldNot(Receive()) err = instance.Stop()