test concurrent connection closing
@@ -53,3 +53,41 @@ func TestWebsocketListen(t *testing.T) {
t.Fatal("got wrong message", out, msg)
}
}
+
+func TestConcurrentClose(t *testing.T) {
+ zero, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/0/ws")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ tpt := &WebsocketTransport{}
+ l, err := tpt.Listen(zero)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer l.Close()
+
+ msg := []byte("HELLO WORLD")
+
+ go func() {
+ d, _ := tpt.Dialer(nil)
+ for i := 0; i < 100; i++ {
+ c, err := d.Dial(l.Multiaddr())
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ go c.Write(msg)
+ go c.Close()
+ }
+ }()
+
+ for i := 0; i < 100; i++ {
+ c, err := l.Accept()
+ if err != nil {
+ t.Fatal(err)
+ }
+ c.Close()
+ }
+}
