github.com/tumi8/quic-go@v0.37.4-tum/closed_conn_test.go (about)

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