Skip to content

Commit

Permalink
Addressed a data race condition in the server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kpumuk committed Sep 24, 2024
1 parent ee0e5dc commit 71468a1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/server/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http/httptest"
"strings"
"sync"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -236,14 +237,14 @@ func TestTarget_DrainWhenEmpty(t *testing.T) {

func TestTarget_DrainRequestsThatCompleteWithinTimeout(t *testing.T) {
n := 3
served := 0
var served int32 = 0

var started sync.WaitGroup
started.Add(n)

target := testTarget(t, func(w http.ResponseWriter, r *http.Request) {
time.Sleep(time.Millisecond * 200)
served++
atomic.AddInt32(&served, 1)
started.Done()
})

Expand All @@ -256,7 +257,7 @@ func TestTarget_DrainRequestsThatCompleteWithinTimeout(t *testing.T) {
started.Wait()
target.Drain(time.Second * 5)

require.Equal(t, n, served)
require.Equal(t, int32(n), served)
}

func TestTarget_DrainRequestsThatNeedToBeCancelled(t *testing.T) {
Expand Down

0 comments on commit 71468a1

Please sign in to comment.