Repository: quic-go/quic-go
Pull request #4814 (2024-12-28 07:58:24)

migrate multiplexer tests away from Ginkgo
Part of #3652. Also fixes tests to properly clean up the multiplexer.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/quic-go/quic-go/pull/4814?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 83.75%. Comparing base [(`9cf118f`)](https://app.codecov.io/gh/quic-go/quic-go/commit/9cf118fc82f0f2f93ba6e4585c0433db332be984?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) to head [(`c4113eb`)](https://app.codecov.io/gh/quic-go/quic-go/commit/c4113eb9692a0005646c98b0d005109a84dc5d62?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #4814      +/-   ##
==========================================
- Coverage   83.86%   83.75%   -0.11%     
==========================================
  Files         149      146       -3     
  Lines       16052    15707     -345     
==========================================
- Hits        13462    13155     -307     
+ Misses       2059     2039      -20     
+ Partials      531      513      -18     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/quic-go/quic-go/pull/4814?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).


Patch:
diff --git a/multiplexer.go b/multiplexer.go
index 85f7f403..cebe7c2e 100644
--- a/multiplexer.go
+++ b/multiplexer.go
@@ -67,7 +67,7 @@ func (m *connMultiplexer) RemoveConn(c indexableConn) error {
 
 	connIndex := m.index(c.LocalAddr())
 	if _, ok := m.conns[connIndex]; !ok {
-		return fmt.Errorf("cannote remove connection, connection is unknown")
+		return fmt.Errorf("cannote remove connection %s, connection is unknown", connIndex)
 	}
 
 	delete(m.conns, connIndex)


Test patch:
diff --git a/multiplexer_test.go b/multiplexer_test.go
index 48590b28..b98dc92c 100644
--- a/multiplexer_test.go
+++ b/multiplexer_test.go
@@ -2,25 +2,32 @@ package quic
 
 import (
 	"net"
+	"testing"
 
-	. "github.com/onsi/ginkgo/v2"
-	. "github.com/onsi/gomega"
+	"github.com/stretchr/testify/require"
 )
 
-var _ = Describe("Multiplexer", func() {
-	It("adds new packet conns", func() {
-		conn1 := NewMockPacketConn(mockCtrl)
-		conn1.EXPECT().LocalAddr().Return(&net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 1234})
-		getMultiplexer().AddConn(conn1)
-		conn2 := NewMockPacketConn(mockCtrl)
-		conn2.EXPECT().LocalAddr().Return(&net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 1235})
-		getMultiplexer().AddConn(conn2)
-	})
-
-	It("panics when the same connection is added twice", func() {
-		conn := NewMockPacketConn(mockCtrl)
-		conn.EXPECT().LocalAddr().Return(&net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 4321}).Times(2)
-		getMultiplexer().AddConn(conn)
-		Expect(func() { getMultiplexer().AddConn(conn) }).To(Panic())
-	})
-})
+type mockIndexableConn struct{ addr net.Addr }
+
+var _ indexableConn = &mockIndexableConn{}
+
+func (m *mockIndexableConn) LocalAddr() net.Addr { return m.addr }
+
+func TestMultiplexerAddNewPacketConns(t *testing.T) {
+	conn1 := &mockIndexableConn{addr: &net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 1234}}
+	getMultiplexer().AddConn(conn1)
+	conn2 := &mockIndexableConn{addr: &net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 1235}}
+	getMultiplexer().AddConn(conn2)
+
+	require.NoError(t, getMultiplexer().RemoveConn(conn1))
+	require.NoError(t, getMultiplexer().RemoveConn(conn2))
+}
+
+func TestMultiplexerPanicsOnDuplicateConn(t *testing.T) {
+	conn := &mockIndexableConn{addr: &net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 4321}}
+	getMultiplexer().AddConn(conn)
+	require.Panics(t, func() { getMultiplexer().AddConn(conn) })
+
+	require.NoError(t, getMultiplexer().RemoveConn(conn))
+	require.ErrorContains(t, getMultiplexer().RemoveConn(conn), "cannote remove connection")
+}
diff --git a/send_stream_test.go b/send_stream_test.go
index f4d3de04..f37ee27b 100644
--- a/send_stream_test.go
+++ b/send_stream_test.go
@@ -156,8 +156,8 @@ func TestSendStreamLargeWrites(t *testing.T) {
 	rand.Read(data)
 	errChan := make(chan error, 1)
 	go func() {
-		defer str.Close()
 		_, err := (&writerWithTimeout{Writer: str, Timeout: time.Second}).Write(data)
+		str.Close()
 		errChan <- err
 	}()
 	select {