You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.9 KiB

lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
  1. // +build release
  2. // The code in here is comprehensive as an integration
  3. // test and is long, hence is only run before releases.
  4. package rpcclient
  5. import (
  6. "bytes"
  7. "errors"
  8. "net"
  9. "regexp"
  10. "testing"
  11. "time"
  12. "github.com/stretchr/testify/require"
  13. "github.com/tendermint/tendermint/libs/log"
  14. )
  15. func TestWSClientReconnectWithJitter(t *testing.T) {
  16. n := 8
  17. maxReconnectAttempts := 3
  18. // Max wait time is ceil(1+0.999) + ceil(2+0.999) + ceil(4+0.999) + ceil(...) = 2 + 3 + 5 = 10s + ...
  19. maxSleepTime := time.Second * time.Duration(((1<<uint(maxReconnectAttempts))-1)+maxReconnectAttempts)
  20. var errNotConnected = errors.New("not connected")
  21. clientMap := make(map[int]*WSClient)
  22. buf := new(bytes.Buffer)
  23. logger := log.NewTMLogger(buf)
  24. for i := 0; i < n; i++ {
  25. c, err := NewWSClient("tcp://foo", "/websocket")
  26. require.Nil(t, err)
  27. c.Dialer = func(string, string) (net.Conn, error) {
  28. return nil, errNotConnected
  29. }
  30. c.SetLogger(logger)
  31. c.maxReconnectAttempts = maxReconnectAttempts
  32. // Not invoking defer c.Stop() because
  33. // after all the reconnect attempts have been
  34. // exhausted, c.Stop is implicitly invoked.
  35. clientMap[i] = c
  36. // Trigger the reconnect routine that performs exponential backoff.
  37. go c.reconnect()
  38. }
  39. stopCount := 0
  40. time.Sleep(maxSleepTime)
  41. for key, c := range clientMap {
  42. if !c.IsActive() {
  43. delete(clientMap, key)
  44. stopCount++
  45. }
  46. }
  47. require.Equal(t, stopCount, n, "expecting all clients to have been stopped")
  48. // Next we have to examine the logs to ensure that no single time was repeated
  49. backoffDurRegexp := regexp.MustCompile(`backoff_duration=(.+)`)
  50. matches := backoffDurRegexp.FindAll(buf.Bytes(), -1)
  51. seenMap := make(map[string]int)
  52. for i, match := range matches {
  53. if origIndex, seen := seenMap[string(match)]; seen {
  54. t.Errorf("match #%d (%q) was seen originally at log entry #%d", i, match, origIndex)
  55. } else {
  56. seenMap[string(match)] = i
  57. }
  58. }
  59. }