Skip to content

Commit

Permalink
add test request retry to deal with floating tls fails (#3524)
Browse files Browse the repository at this point in the history
<!-- Provide a general summary of your changes in the Title above -->
Add hacky retry to deal with tls errors

Upon investigation it seems to be some language bug

[somewhat similar issue](golang/go#35373)

tuning tls client doesn't help to resolve this issue

by running tests multiple times

```
go test -v -run TestAPIMutualTLS -count 50 ./gateway
```
Tests fails 2-3 times and uses 1 retry to pass

## Description
<!-- Describe your changes in detail -->

## Related Issue
<!-- This project only accepts pull requests related to open issues -->
<!-- If suggesting a new feature or change, please discuss it in an issue first -->
<!-- If fixing a bug, there should be an issue describing it with steps to reproduce -->
<!-- Please link to the issue here -->

## Motivation and Context
<!-- Why is this change required? What problem does it solve? -->

## How This Has Been Tested
<!-- Please describe in detail how you tested your changes -->
<!-- Include details of your testing environment, and the tests you ran to see how your change affects other areas of
the code, etc. -->

## Screenshots (if appropriate)

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality)

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes that apply -->
<!-- If you're unsure about any of these, don't hesitate to ask; we're here to help! -->
- [ ] Make sure you are requesting to **pull a topic/feature/bugfix branch** (right side). If pulling from your own
      fork, don't request your `master`!
- [ ] Make sure you are making a pull request against the **`master` branch** (left side). Also, you should start
      *your branch* off *our latest `master`*.
- [ ] My change requires a change to the documentation.
  - [ ] If you've changed APIs, describe what needs to be updated in the documentation.
  - [ ] If new config option added, ensure that it can be set via ENV variable
- [ ] I have updated the documentation accordingly.
- [ ] Modules and vendor dependencies have been updated; run `go mod tidy && go mod vendor`
- [ ] When updating library version must provide reason/explanation for this update.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
- [ ] Check your code additions will not fail linting checks:
  - [ ] `go fmt -s`
  - [ ] `go vet`
  • Loading branch information
Sergey Petrunin authored Apr 8, 2021
1 parent f0eddc5 commit 353fbb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions storage/kv/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
var _ Store = (*Consul)(nil)

func TestConsul_Get(t *testing.T) {
t.Skip()

store, err := NewConsul(config.Global().KV.Consul)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions test/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,21 @@ func (r HTTPTestRunner) Run(t testing.TB, testCases ...TestCase) (*http.Response
t.Errorf("[%d] Request build error: %s", ti, err.Error())
continue
}

const maxRetryCount = 2
retryCount := 0
retry:

lastResponse, lastError = r.Do(req, &tc)
tcJSON, _ := json.Marshal(tc)

if lastError != nil {
if retryCount < maxRetryCount && (strings.Contains(lastError.Error(), "broken pipe") ||
strings.Contains(lastError.Error(), "protocol wrong type for socket")) {
retryCount++
goto retry
}

if tc.ErrorMatch != "" {
if !strings.Contains(lastError.Error(), tc.ErrorMatch) {
t.Errorf("[%d] Expect error `%s` to contain `%s`. %s", ti, lastError.Error(), tc.ErrorMatch, string(tcJSON))
Expand Down

0 comments on commit 353fbb3

Please sign in to comment.