Skip to content

Commit 802bed0

Browse files
author
Sophia Castellarin
authored
Fix retry panic (#48)
* Consolidate code files into internal package * Set default backoff strategy * Disable retries by default
1 parent 8846e65 commit 802bed0

File tree

10 files changed

+20
-15
lines changed

10 files changed

+20
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ httptest
1414

1515
# macOS
1616
.DS_Store
17+
18+
*.vscode/

config.go renamed to internal/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package main
15+
package internal
1616

1717
import (
1818
"fmt"
@@ -56,9 +56,9 @@ func FromEnv() (*Config, error) {
5656
printFailedOnly = true
5757
}
5858

59-
enableRetries := true
60-
if getEnv("ENABLE_RETRIES", "true") == "false" {
61-
enableRetries = false
59+
enableRetries := false
60+
if getEnv("ENABLE_RETRIES", "false") == "true" {
61+
enableRetries = true
6262
}
6363

6464
retryCount, err := strconv.Atoi(getEnv("DEFAULT_RETRY_COUNT", "2"))

coordinator.go renamed to internal/coordinator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package main
15+
package internal
1616

1717
import (
1818
"sync"

dynamic.go renamed to internal/dynamic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package main
15+
package internal
1616

1717
import (
1818
"fmt"

http.go renamed to internal/http.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package main
15+
package internal
1616

1717
import (
1818
"bytes"
@@ -112,6 +112,7 @@ func SendHTTPRequest(config *HTTPRequestConfig) (*http.Response, []byte, error)
112112
if config.MaxRetries > 0 {
113113
client.RetryMax = config.MaxRetries
114114
client.CheckRetry = config.RetryCallback
115+
client.Backoff = retryablehttp.DefaultBackoff
115116
} else {
116117
// Don't retry requests
117118
client.CheckRetry = func(ctx context.Context, resp *http.Response, inErr error) (bool, error) { return false, nil }

output.go renamed to internal/output.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package main
15+
package internal
1616

1717
import (
1818
"fmt"

parser.go renamed to internal/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package main
15+
package internal
1616

1717
import (
1818
"fmt"

tester.go renamed to internal/tester.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package main
15+
package internal
1616

1717
import (
1818
"context"

utils.go renamed to internal/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package main
15+
package internal
1616

1717
import (
1818
"fmt"

main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121

2222
"go.uber.org/zap"
2323
"go.uber.org/zap/zapcore"
24+
25+
ht "github.com/nytimes/httptest/internal"
2426
)
2527

2628
var (
@@ -78,12 +80,12 @@ func main() {
7880
fmt.Printf("httptest: %s %s %s\n", BuildCommit, BuildBranch, BuildTime)
7981

8082
// Get and apply config
81-
config, err := FromEnv()
83+
config, err := ht.FromEnv()
8284
if err != nil {
8385
log.Fatalf("error: failed to parse config: %s", err)
8486
}
8587

86-
if err := ApplyConfig(config); err != nil {
88+
if err := ht.ApplyConfig(config); err != nil {
8789
log.Fatalf("error: failed to apply config: %s", err)
8890
}
8991

@@ -92,12 +94,12 @@ func main() {
9294
zap.ReplaceGlobals(logger)
9395

9496
// Parse and run tests
95-
tests, err := ParseAllTestsInDirectory(config.TestDirectory)
97+
tests, err := ht.ParseAllTestsInDirectory(config.TestDirectory)
9698
if err != nil {
9799
log.Fatalf("error: failed to parse tests: %s", err)
98100
}
99101

100-
if !RunTests(tests, config) {
102+
if !ht.RunTests(tests, config) {
101103
os.Exit(1)
102104
}
103105

0 commit comments

Comments
 (0)