Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cannium committed Nov 8, 2018
1 parent c77a0a0 commit 6ccb06b
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,57 @@ var _ = Describe("Transport", func() {
Expect(protocols[0]).To(Equal(ma.P_QUIC))
})
})

var _ = Describe("Port reuse", func() {
var c *connManager
BeforeEach(func() {
c = newConnManager()
})
It("reuse IPv4 port", func() {
addr, _ := ma.NewMultiaddr("/ip4/0.0.0.0/udp/40002/quic")
listenConn, err := c.listenUDP(addr)
Expect(err).ToNot(HaveOccurred())

dialConn, err := c.GetConnForAddr("udp4", "127.0.0.1:40003")
Expect(err).ToNot(HaveOccurred())
Expect(dialConn).To(Equal(listenConn))
listenConn.Close()
})
It("reuse IPv6 port", func() {
addr, _ := ma.NewMultiaddr("/ip6/::/udp/40002/quic")
listenConn, err := c.listenUDP(addr)
Expect(err).ToNot(HaveOccurred())

dialConn, err := c.GetConnForAddr("udp6", "[::1]:40003")
Expect(err).ToNot(HaveOccurred())
Expect(dialConn).To(Equal(listenConn))
listenConn.Close()
})
It("listen after dial won't reuse conn", func() {
dialConn, err := c.GetConnForAddr("udp4", "127.0.0.1:40003")
Expect(err).ToNot(HaveOccurred())

addr, _ := ma.NewMultiaddr("/ip4/0.0.0.0/udp/40002/quic")
listenConn, err := c.listenUDP(addr)
Expect(err).ToNot(HaveOccurred())
Expect(listenConn).ToNot(Equal(dialConn))

dialConn.Close()
listenConn.Close()
})
It("use listen conn by default", func() {
dialConn, err := c.GetConnForAddr("udp4", "127.0.0.1:40003")
Expect(err).ToNot(HaveOccurred())

addr, _ := ma.NewMultiaddr("/ip4/0.0.0.0/udp/40002/quic")
listenConn, err := c.listenUDP(addr)
Expect(err).ToNot(HaveOccurred())

dialConn2, err := c.GetConnForAddr("udp4", "1.2.3.4:40004")
Expect(err).ToNot(HaveOccurred())
Expect(dialConn2).To(Equal(listenConn))

dialConn.Close()
listenConn.Close()
})
})

0 comments on commit 6ccb06b

Please sign in to comment.