github.com/quic-go/quic-go@v0.44.0/closed_conn_test.go (about)

     1  package quic
     2  
     3  import (
     4  	"net"
     5  
     6  	"github.com/quic-go/quic-go/internal/utils"
     7  
     8  	. "github.com/onsi/ginkgo/v2"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("Closed local connection", func() {
    13  	It("repeats the packet containing the CONNECTION_CLOSE frame", func() {
    14  		written := make(chan net.Addr, 1)
    15  		conn := newClosedLocalConn(func(addr net.Addr, _ packetInfo) { written <- addr }, utils.DefaultLogger)
    16  		addr := &net.UDPAddr{IP: net.IPv4(127, 1, 2, 3), Port: 1337}
    17  		for i := 1; i <= 20; i++ {
    18  			conn.handlePacket(receivedPacket{remoteAddr: addr})
    19  			if i == 1 || i == 2 || i == 4 || i == 8 || i == 16 {
    20  				Expect(written).To(Receive(Equal(addr))) // receive the CONNECTION_CLOSE
    21  			} else {
    22  				Expect(written).ToNot(Receive())
    23  			}
    24  		}
    25  	})
    26  })