]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: retry Up() in up/down test
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 10 Feb 2021 00:01:37 +0000 (01:01 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Wed, 10 Feb 2021 00:01:37 +0000 (01:01 +0100)
We're loosing our ownership of the port when bringing the device down,
which means another test process could reclaim it. Avoid this by
retrying for 4 seconds.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
device/device_test.go

index c17b35093e63b8163e886a2c8a034b86cc9807f3..02b1c35a3b4451c7b2c2e704aaa366177a7f456f 100644 (file)
@@ -8,6 +8,7 @@ package device
 import (
        "bytes"
        "encoding/hex"
+       "errors"
        "fmt"
        "io/ioutil"
        "math/rand"
@@ -16,6 +17,7 @@ import (
        "runtime/pprof"
        "sync"
        "sync/atomic"
+       "syscall"
        "testing"
        "time"
 
@@ -211,8 +213,17 @@ func TestUpDown(t *testing.T) {
                        go func(d *Device) {
                                defer wg.Done()
                                for i := 0; i < itrials; i++ {
-                                       if err := d.Up(); err != nil {
-                                               t.Errorf("failed up bring up device: %v", err)
+                                       start := time.Now()
+                                       for {
+                                               if err := d.Up(); err != nil {
+                                                       if errors.Is(err, syscall.EADDRINUSE) && time.Now().Sub(start) < time.Second*4 {
+                                                               // Some other test process is racing with us, so try again.
+                                                               time.Sleep(time.Millisecond * 10)
+                                                               continue
+                                                       }
+                                                       t.Errorf("failed up bring up device: %v", err)
+                                               }
+                                               break
                                        }
                                        time.Sleep(time.Duration(rand.Intn(int(time.Nanosecond * (0x10000 - 1)))))
                                        if err := d.Down(); err != nil {