From ed266f51a70be2352dc424972e50ff4250c00eff Mon Sep 17 00:00:00 2001 From: Johnathan Howell Date: Mon, 19 Sep 2016 18:47:03 -0400 Subject: [PATCH] add TestConcurrentUPNP --- upnp_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/upnp_test.go b/upnp_test.go index 8634075..c135d92 100644 --- a/upnp_test.go +++ b/upnp_test.go @@ -4,6 +4,26 @@ import ( "testing" ) +// TestConcurrentUPNP tests that several threads calling Discover() concurrently +// succeed. +func TestConcurrentUPNP(t *testing.T) { + // verify that a router exists + _, err := Discover() + if err != nil { + t.Fatal(err) + } + + // now try to concurrently Discover() using 10 threads + for i := 0; i < 10; i++ { + go func() { + _, err := Discover() + if err != nil { + t.Fatal(err) + } + }() + } +} + func TestIGD(t *testing.T) { // connect to router d, err := Discover()