Skip to content

Commit c342b1e

Browse files
mirskifapranav.goyal
authored andcommitted
Add small sleep after GC in test to improve reliability
1 parent 3a81414 commit c342b1e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

internal/sensitive/sensitive_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"runtime"
2222
"testing"
23+
"time"
2324
)
2425

2526
func TestString(t *testing.T) {
@@ -60,6 +61,7 @@ func TestMultipleExpansions(t *testing.T) {
6061
for i := range 10 {
6162
s.Write([]byte(fmt.Sprintf("-%d", i)))
6263
runtime.GC()
64+
time.Sleep(10 * time.Millisecond)
6365
}
6466
expected := "initial-0-1-2-3-4-5-6-7-8-9"
6567
actual := string(append([]byte(nil), []byte(s.String())...)) // Copy bytes from the string, not just a clone of the pointer
@@ -131,6 +133,7 @@ func TestGCRedaction(t *testing.T) {
131133

132134
t.Logf("Before GC: []byte='%s' (%x); string='%s' (%x)", string(asByte), asByte, asString, asString)
133135
runtime.GC()
136+
time.Sleep(10 * time.Millisecond)
134137

135138
stringCopy := string(append([]byte(nil), []byte(asString)...)) // Copy bytes from the string, not just a clone of the pointer
136139
byteCopy := make([]byte, len(asByte))

0 commit comments

Comments
 (0)