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. "context"
  9. "errors"
  10. "net"
  11. "regexp"
  12. "testing"
  13. "time"
  14. "github.com/stretchr/testify/require"
  15. )
  16. func TestWSClientReconnectWithJitter(t *testing.T) {
  17. n := 8
  18. var maxReconnectAttempts uint = 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. ctx, cancel := context.WithCancel(context.Background())
  22. defer cancel()
  23. var errNotConnected = errors.New("not connected")
  24. clientMap := make(map[int]*WSClient)
  25. buf := new(bytes.Buffer)
  26. for i := 0; i < n; i++ {
  27. c, err := NewWS("tcp://foo", "/websocket")
  28. require.NoError(t, err)
  29. c.Dialer = func(string, string) (net.Conn, error) {
  30. return nil, errNotConnected
  31. }
  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(ctx)
  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. }