Skip to content

Commit

Permalink
Fix false-positive goroutine leak error
Browse files Browse the repository at this point in the history
Use checkGoroutineLeaks everywhere.
  • Loading branch information
enobufs authored and Sean-Der committed Jan 6, 2024
1 parent 104bc8c commit efb40a3
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2382,8 +2382,7 @@ func (c *fakeEchoConn) SetWriteDeadline(time.Time) error { return nil }
func TestRoutineLeak(t *testing.T) {
loggerFactory := logging.NewDefaultLoggerFactory()
t.Run("Close failed", func(t *testing.T) {
runtime.GC()
n0 := runtime.NumGoroutine()
checkGoroutineLeaks(t)

conn := newFakeEchoConn(io.EOF)
a, err := Client(Config{NetConn: conn, LoggerFactory: loggerFactory})
Expand All @@ -2403,12 +2402,9 @@ func TestRoutineLeak(t *testing.T) {
t.Errorf("closeWriteLoopCh is expected to be closed, but not")
}
_ = a
runtime.GC()
assert.Equal(t, n0, runtime.NumGoroutine(), "goroutine is leaked")
})
t.Run("Connection closed by remote host", func(t *testing.T) {
runtime.GC()
n0 := runtime.NumGoroutine()
checkGoroutineLeaks(t)

conn := newFakeEchoConn(nil)
a, err := Client(Config{NetConn: conn, LoggerFactory: loggerFactory})
Expand All @@ -2429,8 +2425,6 @@ func TestRoutineLeak(t *testing.T) {
default:
t.Errorf("closeWriteLoopCh is expected to be closed, but not")
}
runtime.GC()
assert.Equal(t, n0, runtime.NumGoroutine(), "goroutine is leaked")
})
}

Expand Down Expand Up @@ -2673,13 +2667,7 @@ loop:
}

func TestAssociation_Shutdown(t *testing.T) {
runtime.GC()
n0 := runtime.NumGoroutine()

defer func() {
runtime.GC()
assert.Equal(t, n0, runtime.NumGoroutine(), "goroutine is leaked")
}()
checkGoroutineLeaks(t)

a1, a2, err := createAssocs(t)
require.NoError(t, err)
Expand Down Expand Up @@ -2717,13 +2705,7 @@ func TestAssociation_Shutdown(t *testing.T) {
}

func TestAssociation_ShutdownDuringWrite(t *testing.T) {
runtime.GC()
n0 := runtime.NumGoroutine()

defer func() {
runtime.GC()
assert.Equal(t, n0, runtime.NumGoroutine(), "goroutine is leaked")
}()
checkGoroutineLeaks(t)

a1, a2, err := createAssocs(t)
require.NoError(t, err)
Expand Down Expand Up @@ -2934,13 +2916,7 @@ func TestAssociation_HandlePacketInCookieWaitState(t *testing.T) {
}

func TestAssociation_Abort(t *testing.T) {
runtime.GC()
n0 := runtime.NumGoroutine()

defer func() {
runtime.GC()
assert.Equal(t, n0, runtime.NumGoroutine(), "goroutine is leaked")
}()
checkGoroutineLeaks(t)

a1, a2, err := createAssocs(t)
require.NoError(t, err)
Expand Down

0 comments on commit efb40a3

Please sign in to comment.