leak_test.go 1.6 KB

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