From c54b0c0ca1faad239863b70f4ecb1d2a68d1a04a Mon Sep 17 00:00:00 2001 From: Aditya Manthramurthy Date: Tue, 5 Mar 2019 08:04:17 -0800 Subject: [PATCH] Fix a race in tests (#7326) --- cmd/test-utils_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go index e8f688c38..de3dc7cdf 100644 --- a/cmd/test-utils_test.go +++ b/cmd/test-utils_test.go @@ -408,8 +408,19 @@ func resetGlobalConfigPath() { } func resetGlobalServiceDoneCh() { - close(GlobalServiceDoneCh) - GlobalServiceDoneCh = make(chan struct{}) + // Repeatedly send on the service done channel, so that + // listening go-routines will quit. This works better than + // closing the channel - closing introduces a new race, as the + // current thread writes to the variable, and other threads + // listening on it, read from it. +loop: + for { + select { + case GlobalServiceDoneCh <- struct{}{}: + default: + break loop + } + } } // sets globalObjectAPI to `nil`.