Skip to content

Commit

Permalink
Merge branch 'master' into pq/remove_polling
Browse files Browse the repository at this point in the history
  • Loading branch information
gdey committed Aug 31, 2018
2 parents cf1812a + ccc981b commit 7b30a8c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Expand Up @@ -2,20 +2,21 @@ sudo: false
language: go

go:
- 1.8.x
- 1.9.x
- tip
- "stable"
- "1.10.4"
- "1.9.x"
- "1.8.x"

matrix:
allow_failures:
- go: tip
fast_finish: true

before_script:
- go get -u github.com/golang/lint/golint
- go get -u golang.org/x/lint/golint

script:
- go test -v --race ./...
- go test --race ./...

after_script:
- test -z "$(gofmt -s -l -w . | tee /dev/stderr)"
Expand Down
10 changes: 8 additions & 2 deletions example_test.go
Expand Up @@ -23,12 +23,18 @@ func ExampleNewWatcher() {
go func() {
for {
select {
case event := <-watcher.Events:
case event, ok := <-watcher.Events:
if !ok {
return
}
log.Println("event:", event)
if event.Op&fsnotify.Write == fsnotify.Write {
log.Println("modified file:", event.Name)
}
case err := <-watcher.Errors:
case err, ok := <-watcher.Errors:
if !ok {
return
}
log.Println("error:", err)
}
}
Expand Down
6 changes: 6 additions & 0 deletions inotify_test.go
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"
"testing"
"time"
)
Expand Down Expand Up @@ -390,9 +391,12 @@ func TestInotifyOverflow(t *testing.T) {

errChan := make(chan error, numDirs*numFiles)

// All events need to be in the inotify queue before pulling events off it to trigger this error.
wg := sync.WaitGroup{}
for dn := 0; dn < numDirs; dn++ {
testSubdir := fmt.Sprintf("%s/%d", testDir, dn)

wg.Add(1)
go func() {
for fn := 0; fn < numFiles; fn++ {
testFile := fmt.Sprintf("%s/%d", testSubdir, fn)
Expand All @@ -409,8 +413,10 @@ func TestInotifyOverflow(t *testing.T) {
continue
}
}
wg.Done()
}()
}
wg.Wait()

creates := 0
overflows := 0
Expand Down
22 changes: 21 additions & 1 deletion integration_darwin_test.go
Expand Up @@ -7,19 +7,39 @@ package fsnotify
import (
"os"
"path/filepath"
"strconv"
"strings"
"testing"
"time"

"golang.org/x/sys/unix"
)

// darwinVersion returns version os Darwin (17 is macOS 10.13).
func darwinVersion() (int, error) {
s, err := unix.Sysctl("kern.osrelease")
if err != nil {
return 0, err
}
s = strings.Split(s, ".")[0]
return strconv.Atoi(s)
}

// testExchangedataForWatcher tests the watcher with the exchangedata operation on macOS.
//
// This is widely used for atomic saves on macOS, e.g. TextMate and in Apple's NSDocument.
//
// See https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/exchangedata.2.html
// Also see: https://github.com/textmate/textmate/blob/cd016be29489eba5f3c09b7b70b06da134dda550/Frameworks/io/src/swap_file_data.cc#L20
func testExchangedataForWatcher(t *testing.T, watchDir bool) {
osVersion, err := darwinVersion()
if err != nil {
t.Fatal("unable to get Darwin version:", err)
}
if osVersion >= 17 {
t.Skip("Exchangedata is deprecated in macOS 10.13")
}

// Create directory to watch
testDir1 := tempMkdir(t)

Expand Down Expand Up @@ -55,7 +75,7 @@ func testExchangedataForWatcher(t *testing.T, watchDir bool) {
// Receive errors on the error channel on a separate goroutine
go func() {
for err := range watcher.Errors {
t.Fatalf("error received: %s", err)
t.Errorf("error received: %s", err)
}
}()

Expand Down
16 changes: 8 additions & 8 deletions integration_test.go
Expand Up @@ -194,7 +194,7 @@ func TestFsnotifyMultipleCreates(t *testing.T) {
// Receive errors on the error channel on a separate goroutine
go func() {
for err := range watcher.Errors {
t.Fatalf("error received: %s", err)
t.Errorf("error received: %s", err)
}
}()

Expand Down Expand Up @@ -339,7 +339,7 @@ func TestFsnotifyDirOnly(t *testing.T) {
// Receive errors on the error channel on a separate goroutine
go func() {
for err := range watcher.Errors {
t.Fatalf("error received: %s", err)
t.Errorf("error received: %s", err)
}
}()

Expand Down Expand Up @@ -444,7 +444,7 @@ func TestFsnotifyDeleteWatchedDir(t *testing.T) {
// Receive errors on the error channel on a separate goroutine
go func() {
for err := range watcher.Errors {
t.Fatalf("error received: %s", err)
t.Errorf("error received: %s", err)
}
}()

Expand Down Expand Up @@ -489,7 +489,7 @@ func TestFsnotifySubDir(t *testing.T) {
// Receive errors on the error channel on a separate goroutine
go func() {
for err := range watcher.Errors {
t.Fatalf("error received: %s", err)
t.Errorf("error received: %s", err)
}
}()

Expand Down Expand Up @@ -581,7 +581,7 @@ func TestFsnotifyRename(t *testing.T) {
// Receive errors on the error channel on a separate goroutine
go func() {
for err := range watcher.Errors {
t.Fatalf("error received: %s", err)
t.Errorf("error received: %s", err)
}
}()

Expand Down Expand Up @@ -663,7 +663,7 @@ func TestFsnotifyRenameToCreate(t *testing.T) {
// Receive errors on the error channel on a separate goroutine
go func() {
for err := range watcher.Errors {
t.Fatalf("error received: %s", err)
t.Errorf("error received: %s", err)
}
}()

Expand Down Expand Up @@ -756,7 +756,7 @@ func TestFsnotifyRenameToOverwrite(t *testing.T) {
// Receive errors on the error channel on a separate goroutine
go func() {
for err := range watcher.Errors {
t.Fatalf("error received: %s", err)
t.Errorf("error received: %s", err)
}
}()

Expand Down Expand Up @@ -874,7 +874,7 @@ func TestFsnotifyAttrib(t *testing.T) {
// Receive errors on the error channel on a separate goroutine
go func() {
for err := range watcher.Errors {
t.Fatalf("error received: %s", err)
t.Errorf("error received: %s", err)
}
}()

Expand Down

0 comments on commit 7b30a8c

Please sign in to comment.