From d6d51a2f8becb72f64cbba7e778c29ba85cefb38 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sat, 17 Dec 2022 11:08:41 -0300 Subject: [PATCH] Prevent TestFileWatcherInterval from running on CI This test can fail intermittently. It's fine to run it only locally. We were already doing this for TestSignalSentToProcessGroup. --- Taskfile.yml | 6 ++-- task_test.go | 62 --------------------------------------- watch_test.go | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 65 deletions(-) create mode 100644 watch_test.go diff --git a/Taskfile.yml b/Taskfile.yml index 4d9740ea..45b21b09 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -74,11 +74,11 @@ tasks: cmds: - go test {{catLines .GO_PACKAGES}} - test:signals: - desc: Runs test suite with signals tests included + test:all: + desc: Runs test suite with signals and watch tests included deps: [install, sleepit:build] cmds: - - go test {{catLines .GO_PACKAGES}} -tags signals + - go test {{catLines .GO_PACKAGES}} -tags 'signals watch' test-release: desc: Tests release process without publishing diff --git a/task_test.go b/task_test.go index e5abad13..e620545d 100644 --- a/task_test.go +++ b/task_test.go @@ -10,7 +10,6 @@ import ( "runtime" "strings" "testing" - "time" "github.com/stretchr/testify/assert" @@ -1649,67 +1648,6 @@ func TestEvaluateSymlinksInPaths(t *testing.T) { assert.NoError(t, err) } -func TestFileWatcherInterval(t *testing.T) { - const dir = "testdata/watcher_interval" - expectedOutput := strings.TrimSpace(` -task: Started watching for tasks: default -task: [default] echo "Hello, World!" -Hello, World! -task: [default] echo "Hello, World!" -Hello, World! - `) - - var buff bytes.Buffer - e := &task.Executor{ - Dir: dir, - Stdout: &buff, - Stderr: &buff, - Watch: true, - } - - assert.NoError(t, e.Setup()) - buff.Reset() - - err := os.MkdirAll(filepathext.SmartJoin(dir, "src"), 0755) - assert.NoError(t, err) - - err = os.WriteFile(filepathext.SmartJoin(dir, "src/a"), []byte("test"), 0644) - if err != nil { - t.Fatal(err) - } - - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - - go func(ctx context.Context) { - for { - select { - case <-ctx.Done(): - return - default: - err := e.Run(ctx, taskfile.Call{Task: "default"}) - if err != nil { - return - } - } - } - }(ctx) - - time.Sleep(10 * time.Millisecond) - err = os.WriteFile(filepathext.SmartJoin(dir, "src/a"), []byte("test updated"), 0644) - if err != nil { - t.Fatal(err) - } - time.Sleep(700 * time.Millisecond) - cancel() - assert.Equal(t, expectedOutput, strings.TrimSpace(buff.String())) - buff.Reset() - err = os.RemoveAll(filepathext.SmartJoin(dir, ".task")) - assert.NoError(t, err) - err = os.RemoveAll(filepathext.SmartJoin(dir, "src")) - assert.NoError(t, err) -} - func TestTaskfileWalk(t *testing.T) { tests := []struct { name string diff --git a/watch_test.go b/watch_test.go new file mode 100644 index 00000000..305ab179 --- /dev/null +++ b/watch_test.go @@ -0,0 +1,80 @@ +//go:build watch +// +build watch + +package task_test + +import ( + "bytes" + "context" + "os" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + + "github.com/go-task/task/v3" + "github.com/go-task/task/v3/internal/filepathext" + "github.com/go-task/task/v3/taskfile" +) + +func TestFileWatcherInterval(t *testing.T) { + const dir = "testdata/watcher_interval" + expectedOutput := strings.TrimSpace(` +task: Started watching for tasks: default +task: [default] echo "Hello, World!" +Hello, World! +task: [default] echo "Hello, World!" +Hello, World! + `) + + var buff bytes.Buffer + e := &task.Executor{ + Dir: dir, + Stdout: &buff, + Stderr: &buff, + Watch: true, + } + + assert.NoError(t, e.Setup()) + buff.Reset() + + err := os.MkdirAll(filepathext.SmartJoin(dir, "src"), 0755) + assert.NoError(t, err) + + err = os.WriteFile(filepathext.SmartJoin(dir, "src/a"), []byte("test"), 0644) + if err != nil { + t.Fatal(err) + } + + ctx := context.Background() + ctx, cancel := context.WithCancel(ctx) + + go func(ctx context.Context) { + for { + select { + case <-ctx.Done(): + return + default: + err := e.Run(ctx, taskfile.Call{Task: "default"}) + if err != nil { + return + } + } + } + }(ctx) + + time.Sleep(10 * time.Millisecond) + err = os.WriteFile(filepathext.SmartJoin(dir, "src/a"), []byte("test updated"), 0644) + if err != nil { + t.Fatal(err) + } + time.Sleep(700 * time.Millisecond) + cancel() + assert.Equal(t, expectedOutput, strings.TrimSpace(buff.String())) + buff.Reset() + err = os.RemoveAll(filepathext.SmartJoin(dir, ".task")) + assert.NoError(t, err) + err = os.RemoveAll(filepathext.SmartJoin(dir, "src")) + assert.NoError(t, err) +}