| 1 |
//go:build e2e_testing |
| 2 |
// +build e2e_testing |
| 3 |
|
| 4 |
package e2e |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
"time" |
| 9 |
|
| 10 |
"github.com/slackhq/nebula/cert" |
| 11 |
"github.com/slackhq/nebula/cert_test" |
| 12 |
"github.com/slackhq/nebula/e2e/router" |
| 13 |
"go.uber.org/goleak" |
| 14 |
) |
| 15 |
|
| 16 |
// TestNoGoroutineLeaks brings up two nebula instances, completes a tunnel, |
| 17 |
// stops both, and asserts no goroutines leak past the shutdown. goleak's |
| 18 |
// retry mechanism gives the wg.Wait()-driven goroutines a moment to drain |
| 19 |
// before failing the assertion. |
| 20 |
// |
| 21 |
// Intentionally NOT t.Parallel()'d: concurrent tests would have their own |
| 22 |
// goroutines running and trip the assertion. |
| 23 |
func TestNoGoroutineLeaks(t *testing.T) { |
| 24 |
defer goleak.VerifyNone(t) |
| 25 |
|
| 26 |
ca, _, caKey, _ := cert_test.NewTestCaCert(cert.Version1, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{}) |
| 27 |
myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me", "10.128.0.1/24", nil) |
| 28 |
theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.2/24", nil) |
| 29 |
|
| 30 |
myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr) |
| 31 |
theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr) |
| 32 |
|
| 33 |
myControl.Start() |
| 34 |
theirControl.Start() |
| 35 |
|
| 36 |
r := router.NewR(t, myControl, theirControl) |
| 37 |
assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r) |
| 38 |
|
| 39 |
myControl.Stop() |
| 40 |
theirControl.Stop() |
| 41 |
r.RenderFlow() |
| 42 |
|
| 43 |
// Settle period: Stop() is non-blocking; the wg-driven goroutines need |
| 44 |
// a moment to drain. goleak retries internally too, but a short explicit |
| 45 |
// settle reduces flakes when the suite is busy. |
| 46 |
time.Sleep(50 * time.Millisecond) |
| 47 |
} |