chaos.go 1.7 KB

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