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 denyeart committed Nov 10, 2020
1 parent 901fe6c commit c590e37
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/container/externalbuilder/instance_test.go
Original file line number Diff line number Diff line change
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 c590e37

Please sign in to comment.