Skip to content

Commit d6d51a2

Browse files
committed
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.
1 parent a98b41d commit d6d51a2

File tree

3 files changed

+83
-65
lines changed

3 files changed

+83
-65
lines changed

Taskfile.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ tasks:
7474
cmds:
7575
- go test {{catLines .GO_PACKAGES}}
7676

77-
test:signals:
78-
desc: Runs test suite with signals tests included
77+
test:all:
78+
desc: Runs test suite with signals and watch tests included
7979
deps: [install, sleepit:build]
8080
cmds:
81-
- go test {{catLines .GO_PACKAGES}} -tags signals
81+
- go test {{catLines .GO_PACKAGES}} -tags 'signals watch'
8282

8383
test-release:
8484
desc: Tests release process without publishing

task_test.go

-62
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"runtime"
1111
"strings"
1212
"testing"
13-
"time"
1413

1514
"github.com/stretchr/testify/assert"
1615

@@ -1649,67 +1648,6 @@ func TestEvaluateSymlinksInPaths(t *testing.T) {
16491648
assert.NoError(t, err)
16501649
}
16511650

1652-
func TestFileWatcherInterval(t *testing.T) {
1653-
const dir = "testdata/watcher_interval"
1654-
expectedOutput := strings.TrimSpace(`
1655-
task: Started watching for tasks: default
1656-
task: [default] echo "Hello, World!"
1657-
Hello, World!
1658-
task: [default] echo "Hello, World!"
1659-
Hello, World!
1660-
`)
1661-
1662-
var buff bytes.Buffer
1663-
e := &task.Executor{
1664-
Dir: dir,
1665-
Stdout: &buff,
1666-
Stderr: &buff,
1667-
Watch: true,
1668-
}
1669-
1670-
assert.NoError(t, e.Setup())
1671-
buff.Reset()
1672-
1673-
err := os.MkdirAll(filepathext.SmartJoin(dir, "src"), 0755)
1674-
assert.NoError(t, err)
1675-
1676-
err = os.WriteFile(filepathext.SmartJoin(dir, "src/a"), []byte("test"), 0644)
1677-
if err != nil {
1678-
t.Fatal(err)
1679-
}
1680-
1681-
ctx := context.Background()
1682-
ctx, cancel := context.WithCancel(ctx)
1683-
1684-
go func(ctx context.Context) {
1685-
for {
1686-
select {
1687-
case <-ctx.Done():
1688-
return
1689-
default:
1690-
err := e.Run(ctx, taskfile.Call{Task: "default"})
1691-
if err != nil {
1692-
return
1693-
}
1694-
}
1695-
}
1696-
}(ctx)
1697-
1698-
time.Sleep(10 * time.Millisecond)
1699-
err = os.WriteFile(filepathext.SmartJoin(dir, "src/a"), []byte("test updated"), 0644)
1700-
if err != nil {
1701-
t.Fatal(err)
1702-
}
1703-
time.Sleep(700 * time.Millisecond)
1704-
cancel()
1705-
assert.Equal(t, expectedOutput, strings.TrimSpace(buff.String()))
1706-
buff.Reset()
1707-
err = os.RemoveAll(filepathext.SmartJoin(dir, ".task"))
1708-
assert.NoError(t, err)
1709-
err = os.RemoveAll(filepathext.SmartJoin(dir, "src"))
1710-
assert.NoError(t, err)
1711-
}
1712-
17131651
func TestTaskfileWalk(t *testing.T) {
17141652
tests := []struct {
17151653
name string

watch_test.go

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//go:build watch
2+
// +build watch
3+
4+
package task_test
5+
6+
import (
7+
"bytes"
8+
"context"
9+
"os"
10+
"strings"
11+
"testing"
12+
"time"
13+
14+
"github.com/stretchr/testify/assert"
15+
16+
"github.com/go-task/task/v3"
17+
"github.com/go-task/task/v3/internal/filepathext"
18+
"github.com/go-task/task/v3/taskfile"
19+
)
20+
21+
func TestFileWatcherInterval(t *testing.T) {
22+
const dir = "testdata/watcher_interval"
23+
expectedOutput := strings.TrimSpace(`
24+
task: Started watching for tasks: default
25+
task: [default] echo "Hello, World!"
26+
Hello, World!
27+
task: [default] echo "Hello, World!"
28+
Hello, World!
29+
`)
30+
31+
var buff bytes.Buffer
32+
e := &task.Executor{
33+
Dir: dir,
34+
Stdout: &buff,
35+
Stderr: &buff,
36+
Watch: true,
37+
}
38+
39+
assert.NoError(t, e.Setup())
40+
buff.Reset()
41+
42+
err := os.MkdirAll(filepathext.SmartJoin(dir, "src"), 0755)
43+
assert.NoError(t, err)
44+
45+
err = os.WriteFile(filepathext.SmartJoin(dir, "src/a"), []byte("test"), 0644)
46+
if err != nil {
47+
t.Fatal(err)
48+
}
49+
50+
ctx := context.Background()
51+
ctx, cancel := context.WithCancel(ctx)
52+
53+
go func(ctx context.Context) {
54+
for {
55+
select {
56+
case <-ctx.Done():
57+
return
58+
default:
59+
err := e.Run(ctx, taskfile.Call{Task: "default"})
60+
if err != nil {
61+
return
62+
}
63+
}
64+
}
65+
}(ctx)
66+
67+
time.Sleep(10 * time.Millisecond)
68+
err = os.WriteFile(filepathext.SmartJoin(dir, "src/a"), []byte("test updated"), 0644)
69+
if err != nil {
70+
t.Fatal(err)
71+
}
72+
time.Sleep(700 * time.Millisecond)
73+
cancel()
74+
assert.Equal(t, expectedOutput, strings.TrimSpace(buff.String()))
75+
buff.Reset()
76+
err = os.RemoveAll(filepathext.SmartJoin(dir, ".task"))
77+
assert.NoError(t, err)
78+
err = os.RemoveAll(filepathext.SmartJoin(dir, "src"))
79+
assert.NoError(t, err)
80+
}

0 commit comments

Comments
 (0)