chaos.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package features
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/onsi/ginkgo/v2"
  6. "github.com/fatedier/frp/test/e2e/framework"
  7. )
  8. var _ = ginkgo.Describe("[Feature: Chaos]", func() {
  9. f := framework.NewDefaultFramework()
  10. ginkgo.It("reconnect after frps restart", func() {
  11. serverPort := f.AllocPort()
  12. serverConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
  13. bindAddr = "0.0.0.0"
  14. bindPort = %d
  15. `, serverPort))
  16. remotePort := f.AllocPort()
  17. clientConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
  18. serverPort = %d
  19. log.level = "trace"
  20. [[proxies]]
  21. name = "tcp"
  22. type = "tcp"
  23. localPort = %d
  24. remotePort = %d
  25. `, serverPort, f.PortByName(framework.TCPEchoServerPort), remotePort))
  26. // 1. start frps and frpc, expect request success
  27. ps, _, err := f.RunFrps("-c", serverConfigPath)
  28. framework.ExpectNoError(err)
  29. pc, _, err := f.RunFrpc("-c", clientConfigPath)
  30. framework.ExpectNoError(err)
  31. framework.NewRequestExpect(f).Port(remotePort).Ensure()
  32. // 2. stop frps, expect request failed
  33. _ = ps.Stop()
  34. time.Sleep(200 * time.Millisecond)
  35. framework.NewRequestExpect(f).Port(remotePort).ExpectError(true).Ensure()
  36. // 3. restart frps, expect request success
  37. _, _, err = f.RunFrps("-c", serverConfigPath)
  38. framework.ExpectNoError(err)
  39. time.Sleep(2 * time.Second)
  40. framework.NewRequestExpect(f).Port(remotePort).Ensure()
  41. // 4. stop frpc, expect request failed
  42. _ = pc.Stop()
  43. time.Sleep(200 * time.Millisecond)
  44. framework.NewRequestExpect(f).Port(remotePort).ExpectError(true).Ensure()
  45. // 5. restart frpc, expect request success
  46. _, _, err = f.RunFrpc("-c", clientConfigPath)
  47. framework.ExpectNoError(err)
  48. time.Sleep(time.Second)
  49. framework.NewRequestExpect(f).Port(remotePort).Ensure()
  50. })
  51. })