diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1ebac87 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +on: + push: + branches: + - master + - main + pull_request: +name: Run tests with race detection enabled +jobs: + test: + strategy: + matrix: + go-version: [1.15.x, 1.16.x, 1.17.x] + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v2 + - name: Test + run: go test -race -v ./ diff --git a/pond_blackbox_test.go b/pond_blackbox_test.go index aeaa944..36967b1 100644 --- a/pond_blackbox_test.go +++ b/pond_blackbox_test.go @@ -47,19 +47,17 @@ func TestSubmitAndStopWaitFor(t *testing.T) { pool := pond.New(1, 10) - // Submit tasks + // Submit a long running task var doneCount int32 - for i := 0; i < 10; i++ { - pool.Submit(func() { - time.Sleep(50 * time.Millisecond) - atomic.AddInt32(&doneCount, 1) - }) - } + pool.Submit(func() { + time.Sleep(2 * time.Second) + atomic.AddInt32(&doneCount, 1) + }) - // Wait until all submitted tasks complete - pool.StopAndWaitFor(125 * time.Millisecond) + // Wait 100ms for the task to complete + pool.StopAndWaitFor(50 * time.Millisecond) - assertEqual(t, int32(2), atomic.LoadInt32(&doneCount)) + assertEqual(t, int32(0), atomic.LoadInt32(&doneCount)) } func TestSubmitAndStopWaitForWithEnoughDeadline(t *testing.T) {