Skip to content

Commit

Permalink
Merge pull request #987 from dgageot/fix-979
Browse files Browse the repository at this point in the history
Fix race conditions in TestWatch
  • Loading branch information
r2d4 authored Sep 18, 2018
2 parents 61a8287 + 284cc9e commit f728fd9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/skaffold/watch/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func lastModified(paths []string) (time.Time, error) {
for _, path := range paths {
stat, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
continue // Ignore files that don't exist
}

return last, errors.Wrapf(err, "unable to stat file %s", path)
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/watch/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ func TestWatch(t *testing.T) {

// Run the watcher
ctx, cancel := context.WithCancel(context.Background())
var stopped sync.WaitGroup
stopped.Add(1)
go func() {
err = watcher.Run(ctx, 10*time.Millisecond, somethingChanged.callNoErr)
stopped.Done()
testutil.CheckError(t, false, err)
}()

Expand All @@ -87,6 +90,7 @@ func TestWatch(t *testing.T) {
folderChanged.wait()
somethingChanged.wait()
cancel()
stopped.Wait() // Make sure the watcher is stopped before deleting the tmp folder
})
}
}
Expand Down

0 comments on commit f728fd9

Please sign in to comment.