]> git.ipfire.org Git - thirdparty/wireguard-go.git/commit
device: make test setup more robust
authorJosh Bleecher Snyder <josh@tailscale.com>
Wed, 9 Dec 2020 03:23:56 +0000 (19:23 -0800)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 7 Jan 2021 13:49:44 +0000 (14:49 +0100)
commit3591acba76d30ea7986ff5828cefcd7d8f705be2
tree0202f340d40513e9d53d612f3646390c2a606642
parentca9edf1c6301ed1498a56124d018474a68d04b25
device: make test setup more robust

Picking two free ports to use for a test is difficult.
The free port we selected might no longer be free when we reach
for it a second time.

On my machine, this failure mode led to failures approximately
once per thousand test runs.

Since failures are rare, and threading through and checking for
all possible errors is complicated, fix this with a big hammer:
Retry if either device fails to come up.

Also, if you accidentally pick the same port twice, delightful confusion ensues.
The handshake failures manifest as crypto errors, which look scary.
Again, fix with retries.

To make these retries easier to implement, use testing.T.Cleanup
instead of defer to close devices. This requires Go 1.14.
Update go.mod accordingly. Go 1.13 is no longer supported anyway.

With these fixes, 'go test -race' ran 100,000 times without failure.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
device/device_test.go
go.mod