github.com/TugasAkhir-QUIC/quic-go@v0.0.2-0.20240215011318-d20e25a9054c/closed_conn_test.go (about)

     1  package quic
     2  
     3  import (
     4  	"net"
     5  
     6  	"github.com/TugasAkhir-QUIC/quic-go/internal/protocol"
     7  	"github.com/TugasAkhir-QUIC/quic-go/internal/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  	})
    18  
    19  	It("repeats the packet containing the CONNECTION_CLOSE frame", func() {
    20  		written := make(chan net.Addr, 1)
    21  		conn := newClosedLocalConn(
    22  			func(addr net.Addr, _ packetInfo) { written <- addr },
    23  			protocol.PerspectiveClient,
    24  			utils.DefaultLogger,
    25  		)
    26  		addr := &net.UDPAddr{IP: net.IPv4(127, 1, 2, 3), Port: 1337}
    27  		for i := 1; i <= 20; i++ {
    28  			conn.handlePacket(receivedPacket{remoteAddr: addr})
    29  			if i == 1 || i == 2 || i == 4 || i == 8 || i == 16 {
    30  				Expect(written).To(Receive(Equal(addr))) // receive the CONNECTION_CLOSE
    31  			} else {
    32  				Expect(written).ToNot(Receive())
    33  			}
    34  		}
    35  	})
    36  })