Skip to content

Commit d27ac0a

Browse files
authored
Fixing a flaky test (#4257)
**What type of PR is this?** Bug fix **What does this PR do? Why is it needed?** Adder_test.go generates two random int32 and adds them. There is a high chance that the sum overflow, which is an undefined behavior in C, and then caught by zig cc's ubsan (undefined behavior sanitizer), leading to test failure occasionally. Generating smaller integers to avoid overflow. **Test plan** Run `bazelisk test --runs_per_test 10 --extra_toolchains=@zig_sdk//toolchain:linux_amd64_gnu.2.31 //tests/core/cgo:opts_test` Before: ``` ... ==================== Test output for //tests/core/cgo:opts_test (run 4 of 10): SIGILL: illegal instruction PC=0x4f19a7 m=4 sigcode=2 signal arrived during cgo execution instruction bytes: 0x67 0xf 0xb9 0x0 0x8b 0x45 0xec 0x89 0x45 0xf0 0x8b 0x45 0xf4 0x3 0x45 0xf0 ... ================================================================================ INFO: Found 1 test target... Target //tests/core/cgo:opts_test up-to-date: bazel-bin/tests/core/cgo/opts_test_/opts_test INFO: Elapsed time: 5.981s, Critical Path: 5.52s INFO: 17 processes: 1 internal, 16 processwrapper-sandbox. INFO: Build completed, 1 test FAILED, 17 total actions //tests/core/cgo:opts_test FAILED in 7 out of 10 in 0.1s Stats over 10 runs: max = 0.1s, min = 0.1s, avg = 0.1s, dev = 0.0s ``` After: ``` //tests/core/cgo:opts_test PASSED in 0.1s Stats over 10 runs: max = 0.1s, min = 0.0s, avg = 0.1s, dev = 0.0s ```
1 parent 712ddee commit d27ac0a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tests/core/cgo/adder_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
)
88

99
func TestCPPAdder(t *testing.T) {
10-
a := rand.Int31()
11-
b := rand.Int31()
10+
a := rand.Int31n(100)
11+
b := rand.Int31n(100)
1212
expected := a + b
1313
if result := AddC(a, b); result != expected {
1414
t.Error(fmt.Errorf("wrong result: got %d, expected %d", result, expected))

0 commit comments

Comments
 (0)