Skip to content

Commit

Permalink
fixed wg -race condition in test
Browse files Browse the repository at this point in the history
  • Loading branch information
radovskyb committed Oct 2, 2016
1 parent 444b6ff commit 0e27a17
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ func TestWatcherAdd(t *testing.T) {
t.Error(err)
}

// Make sure len(w.Files) is 5.
// Make sure len(w.Files) is 8.
if len(w.Files) != 8 {
t.Errorf("expected 5 files, found %d", len(w.Files))
t.Errorf("expected 8 files, found %d", len(w.Files))
}

// Make sure w.Names[0] is now equal to testDir.
Expand Down Expand Up @@ -304,9 +304,9 @@ func TestWatcherRemove(t *testing.T) {
t.Error(err)
}

// Make sure len(w.Files) is 5.
// Make sure len(w.Files) is 8.
if len(w.Files) != 8 {
t.Errorf("expected 5 files, found %d", len(w.Files))
t.Errorf("expected 8 files, found %d", len(w.Files))
}

// Now remove the folder from the watchlist.
Expand Down Expand Up @@ -354,16 +354,16 @@ func TestTriggerEvent(t *testing.T) {
wg.Add(1)

go func() {
defer wg.Done()

select {
case event := <-w.Event:
if event.Name() != "triggered event" {
t.Errorf("expected event file name to be triggered event, got %s",
event.Name())
}
wg.Done()
case <-time.After(time.Millisecond * 250):
t.Error("received no event from Event channel")
wg.Done()
}
}()

Expand Down Expand Up @@ -407,6 +407,8 @@ func TestEventAddFile(t *testing.T) {
wg.Add(1)

go func() {
defer wg.Done()

events := 0
for {
select {
Expand All @@ -420,15 +422,14 @@ func TestEventAddFile(t *testing.T) {
events++

if events == len(files) {
wg.Done()
return
}
case <-time.After(time.Millisecond * 250):
for f, e := range files {
if !e {
t.Errorf("received no event for file %s", f)
}
}
wg.Done()
}
}
}()
Expand Down Expand Up @@ -471,6 +472,8 @@ func TestEventDeleteFile(t *testing.T) {
wg.Add(1)

go func() {
defer wg.Done()

events := 0
for {
select {
Expand All @@ -484,15 +487,14 @@ func TestEventDeleteFile(t *testing.T) {
events++

if events == len(files) {
wg.Done()
return
}
case <-time.After(time.Millisecond * 250):
for f, e := range files {
if !e {
t.Errorf("received no event for file %s", f)
}
}
wg.Done()
}
}
}()
Expand Down

0 comments on commit 0e27a17

Please sign in to comment.