Skip to content

Commit

Permalink
Add race cond test
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Jan 13, 2024
1 parent b2f6fb8 commit 49f365d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ jobs:
go-version: 1.18
- name: Test
run: go test -tags=expr_debug -run=TestDebugger -v ./vm

race:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Go 1.21
uses: actions/setup-go@v4
with:
go-version: 1.21
- name: Test
run: go test -race .
20 changes: 20 additions & 0 deletions expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"reflect"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -2383,3 +2384,22 @@ func TestIssue474(t *testing.T) {
})
}
}

func TestRaceCondition(t *testing.T) {
program, err := expr.Compile(`let foo = 1; foo + 1`, expr.Env(mock.Env{}))
require.NoError(t, err)

var wg sync.WaitGroup

for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
out, err := expr.Run(program, mock.Env{})
require.NoError(t, err)
require.Equal(t, 2, out)
}()
}

wg.Wait()
}

0 comments on commit 49f365d

Please sign in to comment.