Skip to content

Commit

Permalink
fixed data race int test
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Jan 28, 2025
1 parent 45d5c94 commit b37dc2a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/query/session_core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"github.com/streadway/handy/atomic"

Check failure on line 7 in internal/query/session_core_test.go

View workflow job for this annotation

GitHub Actions / unit (1.23.x, macOS)

no required module provides package github.com/streadway/handy/atomic; to add it:

Check failure on line 7 in internal/query/session_core_test.go

View workflow job for this annotation

GitHub Actions / unit (1.22.x, macOS)

no required module provides package github.com/streadway/handy/atomic; to add it:

Check failure on line 7 in internal/query/session_core_test.go

View workflow job for this annotation

GitHub Actions / unit (1.22.x, ubuntu)

no required module provides package github.com/streadway/handy/atomic; to add it:

Check failure on line 7 in internal/query/session_core_test.go

View workflow job for this annotation

GitHub Actions / unit (1.23.x, ubuntu)

no required module provides package github.com/streadway/handy/atomic; to add it:

Check failure on line 7 in internal/query/session_core_test.go

View workflow job for this annotation

GitHub Actions / unit (1.22.x, windows)

no required module provides package github.com/streadway/handy/atomic; to add it:

Check failure on line 7 in internal/query/session_core_test.go

View workflow job for this annotation

GitHub Actions / unit (1.23.x, windows)

no required module provides package github.com/streadway/handy/atomic; to add it:

Check failure on line 7 in internal/query/session_core_test.go

View workflow job for this annotation

GitHub Actions / experiment (1.23.x, nightly, ubuntu)

no required module provides package github.com/streadway/handy/atomic; to add it:
"github.com/stretchr/testify/require"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Query"
Expand All @@ -26,11 +27,11 @@ func TestSessionCoreCancelAttachOnDone(t *testing.T) {
done chan struct{}
startRecv = make(chan struct{}, 1)
stopRecv = make(chan struct{}, 1)
recvMsgCounter int
recvMsgCounter atomic.Int
)
attachStream.EXPECT().Recv().DoAndReturn(func() (*Ydb_Query.SessionState, error) {
startRecv <- struct{}{}
recvMsgCounter++
recvMsgCounter.Add(1)
select {
case <-done:
return nil, errSessionClosed
Expand All @@ -49,13 +50,13 @@ func TestSessionCoreCancelAttachOnDone(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, core)
<-stopRecv
require.Equal(t, 1, recvMsgCounter)
require.Equal(t, int64(1), recvMsgCounter.Get())
<-startRecv
<-stopRecv
require.Equal(t, 2, recvMsgCounter)
require.Equal(t, int64(2), recvMsgCounter.Get())
<-startRecv
close(done)
require.GreaterOrEqual(t, recvMsgCounter, 2)
require.LessOrEqual(t, recvMsgCounter, 3)
require.GreaterOrEqual(t, recvMsgCounter.Get(), int64(2))
require.LessOrEqual(t, recvMsgCounter.Get(), int64(3))
}, xtest.StopAfter(time.Second))
}

0 comments on commit b37dc2a

Please sign in to comment.