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.

69 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. //go:build release
  2. // +build release
  3. // The code in here is comprehensive as an integration
  4. // test and is long, hence is only run before releases.
  5. package client
  6. import (
  7. "bytes"
  8. "errors"
  9. "net"
  10. "regexp"
  11. "testing"
  12. "time"
  13. "github.com/stretchr/testify/require"
  14. "github.com/tendermint/tendermint/libs/log"
  15. )
  16. func TestWSClientReconnectWithJitter(t *testing.T) {
  17. n := 8
  18. maxReconnectAttempts := 3
  19. // Max wait time is ceil(1+0.999) + ceil(2+0.999) + ceil(4+0.999) + ceil(...) = 2 + 3 + 5 = 10s + ...
  20. maxSleepTime := time.Second * time.Duration(((1<<uint(maxReconnectAttempts))-1)+maxReconnectAttempts)
  21. var errNotConnected = errors.New("not connected")
  22. clientMap := make(map[int]*WSClient)
  23. buf := new(bytes.Buffer)
  24. logger := log.NewTMLogger(buf)
  25. for i := 0; i < n; i++ {
  26. c, err := NewWS("tcp://foo", "/websocket")
  27. require.Nil(t, err)
  28. c.Dialer = func(string, string) (net.Conn, error) {
  29. return nil, errNotConnected
  30. }
  31. c.SetLogger(logger)
  32. c.maxReconnectAttempts = maxReconnectAttempts
  33. // Not invoking defer c.Stop() because
  34. // after all the reconnect attempts have been
  35. // exhausted, c.Stop is implicitly invoked.
  36. clientMap[i] = c
  37. // Trigger the reconnect routine that performs exponential backoff.
  38. go c.reconnect()
  39. }
  40. stopCount := 0
  41. time.Sleep(maxSleepTime)
  42. for key, c := range clientMap {
  43. if !c.IsActive() {
  44. delete(clientMap, key)
  45. stopCount++
  46. }
  47. }
  48. require.Equal(t, stopCount, n, "expecting all clients to have been stopped")
  49. // Next we have to examine the logs to ensure that no single time was repeated
  50. backoffDurRegexp := regexp.MustCompile(`backoff_duration=(.+)`)
  51. matches := backoffDurRegexp.FindAll(buf.Bytes(), -1)
  52. seenMap := make(map[string]int)
  53. for i, match := range matches {
  54. if origIndex, seen := seenMap[string(match)]; seen {
  55. t.Errorf("match #%d (%q) was seen originally at log entry #%d", i, match, origIndex)
  56. } else {
  57. seenMap[string(match)] = i
  58. }
  59. }
  60. }