Skip to content

Commit 5f2df71

Browse files
author
Mike Bland
committed
Ensure watcher tests don't block during shutdown
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 [email protected] 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.
1 parent 6a0f119 commit 5f2df71

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

validator_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
type ValidatorTest struct {
1111
auth_email_file *os.File
1212
done chan bool
13+
update_seen bool
1314
}
1415

1516
func NewValidatorTest(t *testing.T) *ValidatorTest {
@@ -31,7 +32,12 @@ func (vt *ValidatorTest) TearDown() {
3132
func (vt *ValidatorTest) NewValidator(domains []string,
3233
updated chan<- bool) func(string) bool {
3334
return newValidatorImpl(domains, vt.auth_email_file.Name(),
34-
vt.done, func() { updated <- true })
35+
vt.done, func() {
36+
if vt.update_seen == false {
37+
updated <- true
38+
vt.update_seen = true
39+
}
40+
})
3541
}
3642

3743
// This will close vt.auth_email_file.

0 commit comments

Comments
 (0)