Skip to content

Commit caa3c91

Browse files
committed
test(detectors): fix intermittent race in Test_YAMLDetectorFilters
Replace /usr/bin/cat with /usr/bin/true for positive test case and /usr/bin/id with /usr/bin/false for negative test case to avoid interference from background processes that may execute common utilities. Add 200ms delay before buffer clear to ensure all events from test 1 have arrived, preventing race conditions where late events cause false positives in the negative assertion.
1 parent 7ca6f5d commit caa3c91

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

tests/integration/yaml_detector_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ requirements:
465465
- name: sched_process_exec
466466
dependency: required
467467
data_filters:
468-
- pathname=/usr/bin/cat
468+
- pathname=/usr/bin/true
469469
470470
auto_populate:
471471
detected_from: true
@@ -494,32 +494,34 @@ output:
494494
buf.Clear()
495495

496496
// Test 1: Execute matching pathname - should fire
497-
cmd := exec.Command("/usr/bin/cat", "/dev/null")
497+
cmd := exec.Command("/usr/bin/true")
498498
err := cmd.Run()
499-
require.NoError(t, err, "Failed to execute /usr/bin/cat")
499+
require.NoError(t, err, "Failed to execute /usr/bin/true")
500500

501501
time.Sleep(1 * time.Second)
502502

503503
matchedEvt := waitForDetectorEvent(buf, "test_filter_match", 3*time.Second)
504-
assert.NotNil(t, matchedEvt, "Detector should fire for matching pathname /usr/bin/cat")
504+
assert.NotNil(t, matchedEvt, "Detector should fire for matching pathname /usr/bin/true")
505505

506506
if matchedEvt != nil {
507507
matchedPath := getArgValue(matchedEvt, "matched_path")
508-
assert.Contains(t, matchedPath, "/usr/bin/cat", "matched_path should contain /usr/bin/cat")
508+
assert.Contains(t, matchedPath, "/usr/bin/true", "matched_path should contain /usr/bin/true")
509509
}
510510

511+
// Wait for any remaining events from test 1 to arrive before clearing
512+
time.Sleep(200 * time.Millisecond)
513+
511514
// Clear buffer for next test
512515
buf.Clear()
513516

514517
// Test 2: Execute non-matching pathname - should NOT fire
515-
cmd = exec.Command("/usr/bin/id")
516-
err = cmd.Run()
517-
require.NoError(t, err, "Failed to execute /usr/bin/id")
518+
cmd = exec.Command("/usr/bin/false")
519+
_ = cmd.Run() // /usr/bin/false exits with code 1 by design, ignore error
518520

519521
time.Sleep(1 * time.Second)
520522

521523
unmatchedEvt := waitForDetectorEvent(buf, "test_filter_match", 2*time.Second)
522-
assert.Nil(t, unmatchedEvt, "Detector should NOT fire for non-matching pathname /usr/bin/id")
524+
assert.Nil(t, unmatchedEvt, "Detector should NOT fire for non-matching pathname /usr/bin/false")
523525
}
524526

525527
// Test_YAMLDetectorErrorHandling tests graceful handling of invalid YAML and missing fields

0 commit comments

Comments
 (0)