Skip to content

Commit e8ca995

Browse files
authored
(fix): Fixed flaky test TestReadDirSymlink that frequently failed in CI environments due to platform-specific filesystem issues. (#22743)
### Problem The test was failing with high probability in CI with errors like: FSEventStreamStart errors on macOS Path mismatches due to symlink resolution (/var vs /private/var) panic: index out of range [0] when filesystem watching failed ### Root Causes Symlink path inconsistency: macOS resolves /var to /private/var, causing path comparison failures Filesystem watching failures: notify.Watch() can fail on macOS, Docker containers, and restricted CI environments Temporary directory paths: os.MkdirTemp() may return paths containing symlinks that need normalization ### Changes Normalize root path with filepath.EvalSymlinks() at test start Make filesystem watching failures non-fatal (changed from assert to warning log) Fix symlink comparison by using EvalSymlinks on both sides Handle nil event channel gracefully Approved by: @ouyuanning
1 parent 178a1fd commit e8ca995

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

pkg/sql/colexec/external/external_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,21 +389,35 @@ func TestReadDirSymlink(t *testing.T) {
389389

390390
root, err := os.MkdirTemp("", "*")
391391
assert.Nil(t, err)
392+
393+
// Resolve root to its canonical path to handle symlinks (e.g., /var -> /private/var on macOS)
394+
root, err = filepath.EvalSymlinks(root)
395+
assert.Nil(t, err)
396+
392397
t.Cleanup(func() {
393398
_ = os.RemoveAll(root)
394399
})
395400

396401
evChan := make(chan notify.EventInfo, 1024)
397402
err = notify.Watch(filepath.Join(root, "..."), evChan, notify.All)
398-
assert.Nil(t, err)
399-
defer notify.Stop(evChan)
403+
// File system watching may fail on some platforms or in CI environments, so we don't fail the test
404+
if err != nil {
405+
t.Logf("Warning: notify.Watch failed (non-fatal): %v", err)
406+
evChan = nil
407+
}
408+
if evChan != nil {
409+
defer notify.Stop(evChan)
410+
}
400411

401412
testDone := make(chan struct{})
402413
fsLogDone := make(chan struct{})
403414
go func() {
404415
defer func() {
405416
close(fsLogDone)
406417
}()
418+
if evChan == nil {
419+
return
420+
}
407421
for {
408422
select {
409423
case ev := <-evChan:
@@ -446,10 +460,12 @@ func TestReadDirSymlink(t *testing.T) {
446460
err = f.Close()
447461
assert.Nil(t, err)
448462

449-
// ensure symlink is valid
463+
// ensure symlink is valid - compare using EvalSymlinks on both sides
450464
actual, err := filepath.EvalSymlinks(filepath.Join(root, "a", "b", "d"))
451465
assert.Nil(t, err)
452-
assert.Equal(t, filepath.Join(root, "a", "b", "c"), actual)
466+
expected, err := filepath.EvalSymlinks(filepath.Join(root, "a", "b", "c"))
467+
assert.Nil(t, err)
468+
assert.Equal(t, expected, actual)
453469

454470
// read a/b/d/foo
455471
fooPathInB := filepath.Join(root, "a", "b", "d", "foo")

0 commit comments

Comments
 (0)