tunnels_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //go:build e2e_testing
  2. // +build e2e_testing
  3. package e2e
  4. import (
  5. "testing"
  6. "time"
  7. "github.com/slackhq/nebula/e2e/router"
  8. )
  9. func TestDropInactiveTunnels(t *testing.T) {
  10. // The goal of this test is to ensure the shortest inactivity timeout will close the tunnel on both sides
  11. // under ideal conditions
  12. ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
  13. myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me", "10.128.0.1/24", m{"tunnels": m{"drop_inactive": true, "inactivity_timeout": "5s"}})
  14. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", "10.128.0.2/24", m{"tunnels": m{"drop_inactive": true, "inactivity_timeout": "10m"}})
  15. // Share our underlay information
  16. myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
  17. theirControl.InjectLightHouseAddr(myVpnIpNet.Addr(), myUdpAddr)
  18. // Start the servers
  19. myControl.Start()
  20. theirControl.Start()
  21. r := router.NewR(t, myControl, theirControl)
  22. r.Log("Assert the tunnel between me and them works")
  23. assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
  24. r.Log("Go inactive and wait for the tunnels to get dropped")
  25. waitStart := time.Now()
  26. for {
  27. myIndexes := len(myControl.GetHostmap().Indexes)
  28. theirIndexes := len(theirControl.GetHostmap().Indexes)
  29. if myIndexes == 0 && theirIndexes == 0 {
  30. break
  31. }
  32. since := time.Since(waitStart)
  33. r.Logf("my tunnels: %v; their tunnels: %v; duration: %v", myIndexes, theirIndexes, since)
  34. if since > time.Second*30 {
  35. t.Fatal("Tunnel should have been declared inactive after 5 seconds and before 30 seconds")
  36. }
  37. time.Sleep(1 * time.Second)
  38. r.FlushAll()
  39. }
  40. r.Logf("Inactive tunnels were dropped within %v", time.Since(waitStart))
  41. myControl.Stop()
  42. theirControl.Stop()
  43. }