Merge pull request #3464 from krasi-georgiev/flaky-file-discovery-tests-2

Fix flaky file discovery tests - sync the channel draining goroutine
pull/3466/head
Tobias Schmidt 2017-11-13 17:00:37 +01:00 committed by GitHub
commit 6671277b12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -62,12 +62,14 @@ func testFileSD(t *testing.T, prefix, ext string, expect bool) {
// To avoid empty group struct sent from the discovery caused by invalid fsnotify updates,
// drain the channel until we are ready with the test files.
filesReady := make(chan struct{})
fileReady := make(chan struct{})
drainReady := make(chan struct{})
go func() {
for {
select {
case <-ch:
case <-filesReady:
case <-fileReady:
close(drainReady)
return
}
}
@ -77,7 +79,6 @@ func testFileSD(t *testing.T, prefix, ext string, expect bool) {
if err != nil {
t.Fatal(err)
}
defer newf.Close()
f, err := os.Open(filepath.Join(testDir, prefix+ext))
if err != nil {
@ -91,7 +92,8 @@ func testFileSD(t *testing.T, prefix, ext string, expect bool) {
// File is written with the config so stop draining the discovery channel.
// It needs to be before the file closing so that fsnotify triggers a new loop of the discovery service.
close(filesReady)
close(fileReady)
<-drainReady
newf.Close()
timeout := time.After(15 * time.Second)