From 5f2df7167a90fe9c8734a0c12407f53f4f824cd9 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Wed, 13 May 2015 18:30:22 -0400 Subject: [PATCH] Ensure watcher tests don't block during shutdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These test failures from #93 inspired this change: https://travis-ci.org/bitly/google_auth_proxy/jobs/62474406 https://travis-ci.org/bitly/google_auth_proxy/jobs/62474407 Both tests exhibited this pattern: 2015/05/13 22:10:54 validating: is xyzzy@example.com valid? false 2015/05/13 22:10:54 watching interrupted on event: "/tmp/test_auth_emails_300880185": CHMOD 2015/05/13 22:10:54 watching resumed for /tmp/test_auth_emails_300880185 2015/05/13 22:10:54 reloading after event: "/tmp/test_auth_emails_300880185": CHMOD panic: test timed out after 1m0s [snip] goroutine 175 [chan send]: github.com/bitly/google_auth_proxy.(*ValidatorTest).TearDown(0xc2080bc330) /home/travis/gopath/src/github.com/bitly/google_auth_proxy/validator_test.go:27 +0x43 github.com/bitly/google_auth_proxy.TestValidatorOverwriteEmailListViaRenameAndReplace(0xc2080f2480) /home/travis/gopath/src/github.com/bitly/google_auth_proxy/validator_watcher_test.go:103 +0x3b9 [snip] goroutine 177 [chan send]: github.com/bitly/google_auth_proxy.funcĀ·017() /home/travis/gopath/src/github.com/bitly/google_auth_proxy/validator_test.go:34 +0x41 I realized that the spurious CHMOD events were causing calls to `func() { updated <- true }` (from validator_test.go:34), which caused the goroutine running the watcher to block. At the same time, ValidatorTest.TearDown was blocked by trying to send into the `done` channel. The solution was to create a flag that ensured only one value was ever sent into the update channel. --- validator_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/validator_test.go b/validator_test.go index 1047258..0bf0a08 100644 --- a/validator_test.go +++ b/validator_test.go @@ -10,6 +10,7 @@ import ( type ValidatorTest struct { auth_email_file *os.File done chan bool + update_seen bool } func NewValidatorTest(t *testing.T) *ValidatorTest { @@ -31,7 +32,12 @@ func (vt *ValidatorTest) TearDown() { func (vt *ValidatorTest) NewValidator(domains []string, updated chan<- bool) func(string) bool { return newValidatorImpl(domains, vt.auth_email_file.Name(), - vt.done, func() { updated <- true }) + vt.done, func() { + if vt.update_seen == false { + updated <- true + vt.update_seen = true + } + }) } // This will close vt.auth_email_file.