bandwidth_limit.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package features
  2. import (
  3. "fmt"
  4. "strings"
  5. "time"
  6. "github.com/fatedier/frp/test/e2e/framework"
  7. "github.com/fatedier/frp/test/e2e/framework/consts"
  8. "github.com/fatedier/frp/test/e2e/mock/server/streamserver"
  9. "github.com/fatedier/frp/test/e2e/pkg/request"
  10. . "github.com/onsi/ginkgo"
  11. )
  12. var _ = Describe("[Feature: Bandwidth Limit]", func() {
  13. f := framework.NewDefaultFramework()
  14. It("Proxy Bandwidth Limit", func() {
  15. serverConf := consts.DefaultServerConfig
  16. clientConf := consts.DefaultClientConfig
  17. localPort := f.AllocPort()
  18. localServer := streamserver.New(streamserver.TCP, streamserver.WithBindPort(localPort))
  19. f.RunServer("", localServer)
  20. remotePort := f.AllocPort()
  21. clientConf += fmt.Sprintf(`
  22. [tcp]
  23. type = tcp
  24. local_port = %d
  25. remote_port = %d
  26. bandwidth_limit = 10KB
  27. `, localPort, remotePort)
  28. f.RunProcesses([]string{serverConf}, []string{clientConf})
  29. content := strings.Repeat("a", 50*1024) // 5KB
  30. start := time.Now()
  31. framework.NewRequestExpect(f).Port(remotePort).RequestModify(func(r *request.Request) {
  32. r.Body([]byte(content)).Timeout(30 * time.Second)
  33. }).ExpectResp([]byte(content)).Ensure()
  34. duration := time.Now().Sub(start)
  35. framework.ExpectTrue(duration.Seconds() > 7, "100Kb with 10KB limit, want > 7 seconds, but got %d seconds", duration.Seconds())
  36. })
  37. })