From a2fc197efa883ff3804f5469f7ff70975be5aa68 Mon Sep 17 00:00:00 2001 From: liuq19 Date: Wed, 12 Jun 2024 17:29:26 +0800 Subject: [PATCH] test: enhance data race detection --- .github/workflows/unit_test-linux-x64.yml | 7 ++ decoder/decoder_test.go | 35 ---------- encoder/encoder_test.go | 31 --------- internal/decoder/decode_norace.go | 73 +++++++++++++++++++++ internal/decoder/decode_race.go | 80 +++++++++++++++++++++++ internal/decoder/decoder.go | 47 ------------- internal/decoder/decoder_norace_test.go | 60 +++++++++++++++++ internal/decoder/decoder_test.go | 33 ---------- internal/encoder/encode_norace.go | 44 +++++++++++++ internal/encoder/encode_race.go | 54 +++++++++++++++ internal/encoder/encoder.go | 18 ----- internal/encoder/encoder_norace_test.go | 55 ++++++++++++++++ internal/encoder/encoder_test.go | 29 -------- issue_test/issue634_test.go | 3 + issue_test/race_test_go | 71 ++++++++++++++++++++ scripts/test_race.sh | 21 ++++++ 16 files changed, 468 insertions(+), 193 deletions(-) create mode 100644 internal/decoder/decode_norace.go create mode 100644 internal/decoder/decode_race.go create mode 100644 internal/decoder/decoder_norace_test.go create mode 100644 internal/encoder/encode_norace.go create mode 100644 internal/encoder/encode_race.go create mode 100644 internal/encoder/encoder_norace_test.go create mode 100644 issue_test/race_test_go create mode 100755 scripts/test_race.sh diff --git a/.github/workflows/unit_test-linux-x64.yml b/.github/workflows/unit_test-linux-x64.yml index c6f56b76c..f7197794f 100644 --- a/.github/workflows/unit_test-linux-x64.yml +++ b/.github/workflows/unit_test-linux-x64.yml @@ -5,6 +5,7 @@ on: push jobs: build: strategy: + max-parallel: 4 matrix: go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x] runs-on: [self-hosted, X64] @@ -28,9 +29,15 @@ jobs: restore-keys: | ${{ runner.os }}-go- + - name: Data Race + run: | + ./scripts/test_race.sh + - name: PCSP Test run: python3 ./scripts/test_pcsp.py + + - name: Unit Test run: | go test -race -covermode=atomic -coverprofile=coverage.txt ./... diff --git a/decoder/decoder_test.go b/decoder/decoder_test.go index 882aa7990..138b1d127 100644 --- a/decoder/decoder_test.go +++ b/decoder/decoder_test.go @@ -21,7 +21,6 @@ import ( `runtime` `runtime/debug` `strings` - `sync` `testing` `time` @@ -46,40 +45,6 @@ func TestMain(m *testing.M) { m.Run() } -func TestGC(t *testing.T) { - if debugSyncGC { - return - } - var w interface{} - out, err := decode(TwitterJson, &w, true) - if err != nil { - t.Fatal(err) - } - if out != len(TwitterJson) { - t.Fatal(out) - } - wg := &sync.WaitGroup{} - N := 10000 - for i:=0; i test_race.log || true + +if ! grep -q "WARNING: DATA RACE" ./test_race.log; then + echo "TEST FAILED: should data race here" + exit 1 +fi + +go test -v -run=TestRaceDecode -race -count=100 ./issue_test > test_race.log || true + +if ! grep -q "WARNING: DATA RACE" ./test_race.log; then + echo "TEST FAILED: should data race here" + exit 1 +fi + +mv ./issue_test/race_test.go ./issue_test/race_test_go \ No newline at end of file