frp/test/e2e/features/chaos.go

66 lines
1.7 KiB
Go
Raw Normal View History

package features
2021-06-18 08:48:36 +00:00
import (
"fmt"
"time"
2022-08-28 17:02:53 +00:00
"github.com/onsi/ginkgo"
2021-06-18 08:48:36 +00:00
2022-08-28 17:02:53 +00:00
"github.com/fatedier/frp/test/e2e/framework"
2021-06-18 08:48:36 +00:00
)
2022-08-28 17:02:53 +00:00
var _ = ginkgo.Describe("[Feature: Chaos]", func() {
2021-06-18 08:48:36 +00:00
f := framework.NewDefaultFramework()
2022-08-28 17:02:53 +00:00
ginkgo.It("reconnect after frps restart", func() {
2021-06-18 08:48:36 +00:00
serverPort := f.AllocPort()
serverConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
[common]
bind_addr = 0.0.0.0
bind_port = %d
`, serverPort))
remotePort := f.AllocPort()
clientConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
[common]
server_port = %d
log_level = trace
[tcp]
type = tcp
local_port = %d
remote_port = %d
`, serverPort, f.PortByName(framework.TCPEchoServerPort), remotePort))
// 1. start frps and frpc, expect request success
ps, _, err := f.RunFrps("-c", serverConfigPath)
framework.ExpectNoError(err)
pc, _, err := f.RunFrpc("-c", clientConfigPath)
framework.ExpectNoError(err)
framework.NewRequestExpect(f).Port(remotePort).Ensure()
// 2. stop frps, expect request failed
2022-08-28 17:02:53 +00:00
_ = ps.Stop()
2021-06-18 08:48:36 +00:00
time.Sleep(200 * time.Millisecond)
framework.NewRequestExpect(f).Port(remotePort).ExpectError(true).Ensure()
// 3. restart frps, expect request success
_, _, err = f.RunFrps("-c", serverConfigPath)
framework.ExpectNoError(err)
time.Sleep(2 * time.Second)
framework.NewRequestExpect(f).Port(remotePort).Ensure()
// 4. stop frpc, expect request failed
2022-08-28 17:02:53 +00:00
_ = pc.Stop()
2021-06-18 08:48:36 +00:00
time.Sleep(200 * time.Millisecond)
framework.NewRequestExpect(f).Port(remotePort).ExpectError(true).Ensure()
// 5. restart frpc, expect request success
_, _, err = f.RunFrpc("-c", clientConfigPath)
framework.ExpectNoError(err)
time.Sleep(time.Second)
framework.NewRequestExpect(f).Port(remotePort).Ensure()
})
})