fix flaky server unit test

This commit is contained in:
Marten Seemann
2018-08-15 20:29:52 +07:00
parent 7bf5cb6e2a
commit 78f8e1c83e

View File

@@ -310,6 +310,20 @@ var _ = Describe("Server", func() {
Expect(serv.handlePacketImpl(p)).To(Succeed())
Expect(conn.dataWritten.Bytes()).ToNot(BeEmpty())
})
It("sends a PUBLIC_RESET for new connections that don't have the VersionFlag set", func() {
err := serv.handlePacketImpl(&receivedPacket{
remoteAddr: udpAddr,
header: &wire.Header{
IsPublicHeader: true,
},
})
Expect(err).ToNot(HaveOccurred())
Expect(conn.dataWritten.Len()).ToNot(BeZero())
Expect(conn.dataWrittenTo).To(Equal(udpAddr))
Expect(conn.dataWritten.Bytes()[0] & 0x02).ToNot(BeZero()) // check that the ResetFlag is set
})
})
It("setups with the right values", func() {
@@ -455,22 +469,6 @@ var _ = Describe("Server", func() {
ln.Close()
Eventually(done).Should(BeClosed())
})
It("sends a PublicReset for new connections that don't have the VersionFlag set", func() {
conn.dataReadFrom = udpAddr
conn.dataToRead <- []byte{0x08, 0x4c, 0xfa, 0x9f, 0x9b, 0x66, 0x86, 0x19, 0xf6, 0x01}
ln, err := Listen(conn, nil, config)
Expect(err).ToNot(HaveOccurred())
go func() {
defer GinkgoRecover()
_, err := ln.Accept()
Expect(err).ToNot(HaveOccurred())
}()
Eventually(func() int { return conn.dataWritten.Len() }).ShouldNot(BeZero())
Expect(conn.dataWrittenTo).To(Equal(udpAddr))
Expect(conn.dataWritten.Bytes()[0] & 0x02).ToNot(BeZero()) // check that the ResetFlag is set
})
})
var _ = Describe("default source address verification", func() {