2021-06-20 23:57:41 +08:00
|
|
|
package features
|
2021-06-18 16:48:36 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
"github.com/onsi/ginkgo"
|
2021-06-18 16:48:36 +08:00
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
"github.com/fatedier/frp/test/e2e/framework"
|
2021-06-18 16:48:36 +08:00
|
|
|
)
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
var _ = ginkgo.Describe("[Feature: Chaos]", func() {
|
2021-06-18 16:48:36 +08:00
|
|
|
f := framework.NewDefaultFramework()
|
|
|
|
|
2022-08-29 01:02:53 +08:00
|
|
|
ginkgo.It("reconnect after frps restart", func() {
|
2021-06-18 16:48:36 +08: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-29 01:02:53 +08:00
|
|
|
_ = ps.Stop()
|
2021-06-18 16:48:36 +08: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-29 01:02:53 +08:00
|
|
|
_ = pc.Stop()
|
2021-06-18 16:48:36 +08: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()
|
|
|
|
})
|
|
|
|
})
|