Run of fresh-snapshots for golang-github-stvp-go-udp-testing

Try this locally (using silver-platter):

debian-svp new-upstream --snapshot golang-github-stvp-go-udp-testing 

Merge these changes:

Summary

Merged new upstream version: 0.0~git20171103.0.c4434f0 (was: 0.0~git20150316.0.abcd331).

Diff

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ebf8aae
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+go-udp-testing.test
diff --git a/debian/changelog b/debian/changelog
index 3c8f6a2..c929385 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-stvp-go-udp-testing (0.0~git20171103.0.c4434f0-1) UNRELEASED; urgency=medium
+
+  * New upstream snapshot.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Thu, 08 Aug 2019 10:34:56 +0000
+
 golang-github-stvp-go-udp-testing (0.0~git20150316.0.abcd331-2) unstable; urgency=medium
 
   [ Paul Tagliamonte ]
diff --git a/udp.go b/udp.go
index 746e9c0..a7a5a55 100644
--- a/udp.go
+++ b/udp.go
@@ -44,18 +44,21 @@ func getMessage(t *testing.T, body fn) string {
 	start(t)
 	defer stop(t)
 
-	result := make(chan string)
+	body()
 
-	go func() {
-		message := make([]byte, 1024*32)
+	message := make([]byte, 1024*32)
+	var bufLen int
+	for {
 		listener.SetReadDeadline(time.Now().Add(Timeout))
-		n, _, _ := listener.ReadFrom(message)
-		result <- string(message[0:n])
-	}()
-
-	body()
+		n, _, _ := listener.ReadFrom(message[bufLen:])
+		if n == 0 {
+			break
+		} else {
+			bufLen += n
+		}
+	}
 
-	return <-result
+	return string(message[0:bufLen])
 }
 
 func get(t *testing.T, match string, body fn) (got string, equals bool, contains bool) {
@@ -182,3 +185,7 @@ func ShouldReceiveAllAndNotReceiveAny(t *testing.T, expected []string, unexpecte
 		t.Errorf("but got: %#v", got)
 	}
 }
+
+func ReceiveString(t *testing.T, body fn) string {
+	return getMessage(t, body)
+}
diff --git a/udp_test.go b/udp_test.go
index 256dc1c..4303ff2 100644
--- a/udp_test.go
+++ b/udp_test.go
@@ -10,7 +10,7 @@ var (
 	testAddr = ":8126"
 )
 
-func TestAll(t *testing.T) {
+func setup(t *testing.T) net.Conn {
 	udpClient, err := net.DialTimeout("udp", testAddr, time.Second)
 	if err != nil {
 		t.Fatal(err)
@@ -18,6 +18,12 @@ func TestAll(t *testing.T) {
 
 	SetAddr(testAddr)
 
+	return udpClient
+}
+
+func TestAll(t *testing.T) {
+	udpClient := setup(t)
+
 	testValues := [][]interface{}{
 		[]interface{}{"foo", "foo", true, true},
 		[]interface{}{"foo", "bar", false, false},
@@ -72,9 +78,24 @@ func TestAll(t *testing.T) {
 	})
 
 	ShouldReceiveAllAndNotReceiveAny(t, []string{"foo", "bar"}, []string{"fooby", "bars"}, func() {
-		udpClient.Write([]byte("foobizbar"))
+		udpClient.Write([]byte("foo"))
+		udpClient.Write([]byte("biz"))
+		udpClient.Write([]byte("bar"))
 	})
 
 	// This should fail, but it also shouldn't stall out
 	// ShouldReceive(t, "foo", func() {})
 }
+
+func TestRaceConditionInReadingResults(t *testing.T) {
+	udpClient := setup(t)
+
+	ShouldReceiveAllAndNotReceiveAny(t, []string{"foo", "bar", "biz"}, []string{"fooby", "bars"}, func() {
+		time.Sleep(time.Millisecond * 100)
+		udpClient.Write([]byte("foo"))
+		time.Sleep(time.Millisecond * 200)
+		udpClient.Write([]byte("biz"))
+		time.Sleep(time.Millisecond * 500)
+		udpClient.Write([]byte("bar"))
+	})
+}

Full worker log Full build log