Skip to content

Commit

Permalink
Prevent race that occurs after test timeout
Browse files Browse the repository at this point in the history
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 <sykesmat@us.ibm.com>
  • Loading branch information
sykesm authored and mastersingh24 committed Mar 11, 2021
1 parent 6adcbce commit 7214be7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/container/externalbuilder/instance_test.go
Expand Up @@ -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()))
})
})
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 7214be7

Please sign in to comment.