Skip to content

Commit b7dd6b4

Browse files
h9jianggopherbot
authored andcommitted
gopls/internal/filewatcher: move dir with broken symlink to avoid flakiness
For golang/go#74782 Change-Id: I39dafe35af68584239706c0d085ea28ccd5f2486 Reviewed-on: https://go-review.googlesource.com/c/tools/+/691495 Auto-Submit: Hongxiang Jiang <[email protected]> Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent c06cf8d commit b7dd6b4

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

gopls/internal/filewatcher/filewatcher_test.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,35 @@ package foo
194194
goos: []string{"darwin"},
195195
watchErrorPath: "foo",
196196
changes: func(root string, errs chan error) error {
197-
// ├── foo <- 1st
198-
// │ ├── from.go -> ../to.go <- 2nd
199-
// │ └── foo.go <- 4th
200-
// └── to.go <- 3rd
201-
dir := filepath.Join(root, "foo")
202-
if err := os.Mkdir(dir, 0755); err != nil {
197+
// Prepare a dir with with broken symbolic link.
198+
// foo <- 1st
199+
// └── from.go -> root/to.go <- 1st
200+
tmp := filepath.Join(t.TempDir(), "foo")
201+
if err := os.Mkdir(tmp, 0755); err != nil {
203202
return err
204203
}
204+
from := filepath.Join(tmp, "from.go")
205+
205206
to := filepath.Join(root, "to.go")
206-
from := filepath.Join(dir, "from.go")
207207
// Create the symbolic link to a non-existing file. This would
208208
// cause the watch registration to fail.
209209
if err := os.Symlink(to, from); err != nil {
210210
return err
211211
}
212212

213+
// Move the directory containing the broken symlink into place
214+
// to avoids a flaky test where the directory could be watched
215+
// before the symlink is created. See golang/go#74782.
216+
if err := os.Rename(tmp, filepath.Join(root, "foo")); err != nil {
217+
return err
218+
}
219+
220+
// root
221+
// ├── foo <- 2nd (Move)
222+
// │ ├── from.go -> ../to.go <- 2nd (Move)
223+
// │ └── foo.go <- 4th (Create)
224+
// └── to.go <- 3rd (Create)
225+
213226
// Should be able to capture an error from [fsnotify.Watcher.Add].
214227
err := <-errs
215228
if err == nil {
@@ -244,7 +257,7 @@ package foo
244257

245258
// Once the watch registration is done, file events under the
246259
// dir should be captured.
247-
return os.WriteFile(filepath.Join(dir, "foo.go"), []byte("package main"), 0644)
260+
return os.WriteFile(filepath.Join(root, "foo", "foo.go"), []byte("package main"), 0644)
248261
},
249262
expectedEvents: []protocol.FileEvent{
250263
{URI: "foo", Type: protocol.Created},

0 commit comments

Comments
 (0)