mirror of
https://github.com/docker/compose.git
synced 2025-07-26 23:24:05 +02:00
watch: fix a flaky test by ignoring spurious events correctly (#162)
This commit is contained in:
parent
3850a34114
commit
4801d2b1a4
@ -231,6 +231,7 @@ func TestSingleFile(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
f.fsync()
|
||||||
|
|
||||||
d2 := []byte("hello\nworld\n")
|
d2 := []byte("hello\nworld\n")
|
||||||
err = ioutil.WriteFile(path, d2, 0644)
|
err = ioutil.WriteFile(path, d2, 0644)
|
||||||
|
@ -34,7 +34,7 @@ func (d *darwinNotify) isTrackingPath(path string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *darwinNotify) loop() {
|
func (d *darwinNotify) loop() {
|
||||||
ignoredSpuriousEvent := false
|
ignoredSpuriousEvents := make(map[string]bool, 0)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-d.stop:
|
case <-d.stop:
|
||||||
@ -50,8 +50,8 @@ func (d *darwinNotify) loop() {
|
|||||||
// ignore the first event that says the watched directory
|
// ignore the first event that says the watched directory
|
||||||
// has been created. these are fired spuriously on initiation.
|
// has been created. these are fired spuriously on initiation.
|
||||||
if e.Flags&fsevents.ItemCreated == fsevents.ItemCreated {
|
if e.Flags&fsevents.ItemCreated == fsevents.ItemCreated {
|
||||||
if d.isTrackingPath(e.Path) && !ignoredSpuriousEvent {
|
if !ignoredSpuriousEvents[e.Path] && d.isTrackingPath(e.Path) {
|
||||||
ignoredSpuriousEvent = true
|
ignoredSpuriousEvents[e.Path] = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user