Skip to content

Commit b2cd89d

Browse files
h9jianggopherbot
authored andcommitted
gopls/internal/filewatcher: skip file removal event when removing dir
windows-amd64 builder have flacky behavior, it may emit a single dir removal event. freebad-amd64 and linux-amd64 builder report events in reverse order. For golang/go#74525 Change-Id: I14573793aeffa2bbf96321bb2cb0fa1c0555f4c7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/686955 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Hongxiang Jiang <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 85a4574 commit b2cd89d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

gopls/internal/filewatcher/filewatcher_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ package foo
152152
}
153153
},
154154
expectedEvents: []protocol.FileEvent{
155-
{URI: "foo/bar.go", Type: protocol.Deleted},
155+
// We only assert that the directory deletion event exists,
156+
// because file system event behavior is inconsistent across
157+
// platforms when deleting a non-empty directory.
158+
// e.g. windows-amd64 may only emit a single dir removal event,
159+
// freebsd-amd64 report dir removal before file removal,
160+
// linux-amd64 report the reverse order.
161+
// Therefore, the most reliable and cross-platform compatible
162+
// signal is the deletion event for the directory itself.
156163
{URI: "foo", Type: protocol.Deleted},
157164
},
158165
},
@@ -226,6 +233,7 @@ package foo
226233

227234
matched := 0
228235
foundAll := make(chan struct{})
236+
var gots []protocol.FileEvent
229237
var closeWG sync.WaitGroup
230238
closeWG.Add(2)
231239
go func() {
@@ -242,6 +250,7 @@ package foo
242250
// the received events. It confirms not only that all wanted events
243251
// are present, but also that their relative order is preserved.
244252
for events := range eventChan {
253+
gots = append(gots, events...)
245254
for _, got := range events {
246255
if matched == len(tt.expectedEvents) {
247256
break
@@ -267,7 +276,7 @@ package foo
267276
case <-foundAll:
268277
case <-time.After(30 * time.Second):
269278
if matched < len(tt.expectedEvents) {
270-
t.Errorf("missing expected events: %#v\nall expected: %#v", tt.expectedEvents[matched], tt.expectedEvents)
279+
t.Errorf("found %v matching events\nall want: %#v\nall got: %#v", matched, tt.expectedEvents, gots)
271280
}
272281
}
273282

0 commit comments

Comments
 (0)