diff options
Diffstat (limited to 'test/packetimpact')
-rw-r--r-- | test/packetimpact/tests/udp_icmp_error_propagation_test.go | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/test/packetimpact/tests/udp_icmp_error_propagation_test.go b/test/packetimpact/tests/udp_icmp_error_propagation_test.go index c47af9a3e..30dcb336e 100644 --- a/test/packetimpact/tests/udp_icmp_error_propagation_test.go +++ b/test/packetimpact/tests/udp_icmp_error_propagation_test.go @@ -18,7 +18,6 @@ import ( "context" "fmt" "net" - "sync" "syscall" "testing" "time" @@ -301,19 +300,20 @@ func TestICMPErrorDuringUDPRecv(t *testing.T) { t.Fatalf("did not receive message from DUT: %s", err) } - var wg sync.WaitGroup - wg.Add(2) - go func() { + c := make(chan error) + go func(c chan error) { if wantErrno != syscall.Errno(0) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() ret, _, err := dut.RecvWithErrno(ctx, remoteFD, 100, 0) if ret != -1 { - t.Fatalf("recv during ICMP error succeeded unexpectedly, expected (%[1]d) %[1]v", wantErrno) + c <- fmt.Errorf("recv during ICMP error succeeded unexpectedly, expected (%[1]d) %[1]v", wantErrno) + return } if err != wantErrno { - t.Fatalf("recv during ICMP error resulted in error (%[1]d) %[1]v, expected (%[2]d) %[2]v", err, wantErrno) + c <- fmt.Errorf("recv during ICMP error resulted in error (%[1]d) %[1]v, expected (%[2]d) %[2]v", err, wantErrno) + return } } @@ -321,20 +321,23 @@ func TestICMPErrorDuringUDPRecv(t *testing.T) { defer cancel() if ret, _, err := dut.RecvWithErrno(ctx, remoteFD, 100, 0); ret == -1 { - t.Fatalf("recv after ICMP error failed with (%[1]d) %[1]", err) + c <- fmt.Errorf("recv after ICMP error failed with (%[1]d) %[1]", err) + return } - wg.Done() - }() + c <- nil + }(c) - go func() { + cleanChan := make(chan error) + go func(c chan error) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() if ret, _, err := dut.RecvWithErrno(ctx, cleanFD, 100, 0); ret == -1 { - t.Fatalf("recv on clean socket failed with (%[1]d) %[1]", err) + c <- fmt.Errorf("recv on clean socket failed with (%[1]d) %[1]", err) + return } - wg.Done() - }() + c <- nil + }(cleanChan) // TODO(b/155684889) This sleep is to allow time for the DUT to // actually call recv since we want the ICMP error to arrive during the @@ -348,7 +351,14 @@ func TestICMPErrorDuringUDPRecv(t *testing.T) { conn.Send(tb.UDP{DstPort: &cleanPort}) conn.Send(tb.UDP{}) - wg.Wait() + + err, errClean := <-c, <-cleanChan + if errClean != nil { + t.Error(err) + } + if err != nil { + t.Fatal(err) + } }) } } |