From 78f8e1c83e21647b8afd73c68180e8577acd8c18 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 15 Aug 2018 20:29:52 +0700 Subject: [PATCH] fix flaky server unit test --- server_test.go | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/server_test.go b/server_test.go index 39e90b9e..f21dec82 100644 --- a/server_test.go +++ b/server_test.go @@ -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() {