leak_test.go 1.6 KB

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