From 9c20a88bd7d49e275c43cad12f6325c52130dd42 Mon Sep 17 00:00:00 2001
From: Tamir Duberstein <tamird@google.com>
Date: Tue, 26 Mar 2019 20:19:41 -0700
Subject: Remove polling from ICMP test

PiperOrigin-RevId: 240483396
Change-Id: Ie75d3ae38af83f1d92f167ff9ba58fa10f5b372b
---
 pkg/tcpip/network/ipv6/icmp_test.go | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

(limited to 'pkg/tcpip/network/ipv6')

diff --git a/pkg/tcpip/network/ipv6/icmp_test.go b/pkg/tcpip/network/ipv6/icmp_test.go
index 15574bab1..eee09f3af 100644
--- a/pkg/tcpip/network/ipv6/icmp_test.go
+++ b/pkg/tcpip/network/ipv6/icmp_test.go
@@ -15,8 +15,6 @@
 package ipv6
 
 import (
-	"context"
-	"runtime"
 	"strings"
 	"testing"
 	"time"
@@ -181,29 +179,27 @@ func TestLinkResolution(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	// This actually takes about 10 milliseconds, so no need to wait for
-	// a multi-minute go test timeout if something is broken.
-	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
-	defer cancel()
-
 	for {
-		if ctx.Err() != nil {
-			break
+		_, resCh, err := ep.Write(payload, tcpip.WriteOptions{To: &tcpip.FullAddress{NIC: 1, Addr: lladdr1}})
+		if resCh != nil {
+			if err != tcpip.ErrNoLinkAddress {
+				t.Fatalf("ep.Write(_) = _, <non-nil>, %s want _, <non-nil>, tcpip.ErrNoLinkAddress", err)
+			}
+			<-resCh
+			continue
 		}
-		if _, _, err := ep.Write(payload, tcpip.WriteOptions{To: &tcpip.FullAddress{NIC: 1, Addr: lladdr1}}); err == tcpip.ErrNoLinkAddress {
-			// There's something asynchronous going on; yield to let it do its thing.
-			runtime.Gosched()
-		} else if err == nil {
-			break
-		} else {
-			t.Fatal(err)
+		if err != nil {
+			t.Fatalf("ep.Write(_) = _, _, %s", err)
 		}
+		break
 	}
 
 	stats := make(map[header.ICMPv6Type]int)
 	for {
+		// This actually takes about 10 milliseconds, so no need to wait for
+		// a multi-minute go test timeout if something is broken.
 		select {
-		case <-ctx.Done():
+		case <-time.After(2 * time.Second):
 			t.Errorf("timeout waiting for ICMP, got: %#+v", stats)
 			return
 		case icmpInfo := <-c.icmpCh:
-- 
cgit v1.2.3