Skip to content

Commit

Permalink
solove data race
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoranz758 committed Oct 16, 2023
1 parent 0b0e58d commit 34ce7b2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/network/netpoll/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"net"
"reflect"
"sync"
"sync/atomic"
"syscall"
"testing"
Expand Down Expand Up @@ -73,12 +74,15 @@ func TestTransport(t *testing.T) {
t.Run("TestSenseClientDisconnection", func(t *testing.T) {
var onConnFlag int32
var ctxVal context.Context
var mutex sync.Mutex
transporter := NewTransporter(&config.Options{
Addr: addr,
Network: nw,
SenseClientDisconnection: true,
OnConnect: func(ctx context.Context, conn network.Conn) context.Context {
atomic.StoreInt32(&onConnFlag, 1)
mutex.Lock()
defer mutex.Unlock()
ctxVal = ctx
return ctx
},
Expand All @@ -97,6 +101,8 @@ func TestTransport(t *testing.T) {
time.Sleep(100 * time.Millisecond)

assert.Assert(t, atomic.LoadInt32(&onConnFlag) == 1)
mutex.Lock()
defer mutex.Unlock()
assert.DeepEqual(t, "*context.cancelCtx", reflect.TypeOf(ctxVal).String())
})

Expand Down

0 comments on commit 34ce7b2

Please sign in to comment.