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