55 "os"
66 "path/filepath"
77 "strings"
8+ "sync"
89 "testing"
910 "time"
1011
@@ -32,7 +33,9 @@ func TestWatcher(t *testing.T) {
3233 t .Run (tt .name , func (t * testing.T ) {
3334 dir := t .TempDir ()
3435 shouldCreate := atomic.Int64 {}
36+ var wg sync.WaitGroup
3537 notifyFn := func (_ notify.Event , _ string , _ os.FileInfo ) {
38+ defer wg .Done ()
3639 shouldCreate .Inc ()
3740 }
3841 ctl := metric .NewCtl ("test" , prometheus .NewRegistry ())
@@ -67,8 +70,7 @@ func TestWatcher(t *testing.T) {
6770 require .NoError (t , err )
6871 err = f2 .Close ()
6972 require .NoError (t , err )
70-
71- time .Sleep (10 * time .Millisecond )
73+ wg .Add (1 )
7274
7375 f1 , err = os .OpenFile (f1Name , os .O_WRONLY , 0o600 )
7476 require .NoError (t , err )
@@ -77,13 +79,11 @@ func TestWatcher(t *testing.T) {
7779 err = f1 .Close ()
7880 require .NoError (t , err )
7981
80- time .Sleep (10 * time .Millisecond )
81-
8282 err = os .Remove (f1Name )
8383 require .NoError (t , err )
84+ wg .Add (1 )
8485
85- time .Sleep (10 * time .Millisecond )
86-
86+ wg .Wait ()
8787 require .Equal (t , int64 (2 ), shouldCreate .Load ())
8888 })
8989 }
@@ -193,7 +193,10 @@ func TestWatcherPaths(t *testing.T) {
193193
194194 time .Sleep (10 * time .Millisecond )
195195 before := shouldCreate .Load ()
196- w .notify (notify .Create , filename )
196+
197+ resolvedFilename , err := resolvePathLinks (filename )
198+ require .NoError (t , err )
199+ w .notify (notify .Create , resolvedFilename )
197200 after := shouldCreate .Load ()
198201
199202 isNotified := after - before != 0
@@ -216,9 +219,9 @@ func TestCommonPathPrefix(t *testing.T) {
216219
217220func TestResolvePathLinks (t * testing.T ) {
218221 a := assert .New (t )
219- originalDir := t .TempDir ()
222+ originalDir , _ := resolvePathLinks ( t .TempDir () )
220223
221- dirWithLink := t .TempDir ()
224+ dirWithLink , _ := resolvePathLinks ( t .TempDir () )
222225 dirLink := filepath .Join (dirWithLink , "symlink" )
223226 err := os .Symlink (originalDir , dirLink )
224227 if err != nil {
0 commit comments