[go: up one dir, main page]

Skip to content

Commit

Permalink
Fix retry panic (nytimes#48)
Browse files Browse the repository at this point in the history
* Consolidate code files into internal package

* Set default backoff strategy

* Disable retries by default
  • Loading branch information
Sophia Castellarin authored Dec 4, 2023
1 parent 8846e65 commit 802bed0
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ httptest

# macOS
.DS_Store

*.vscode/
8 changes: 4 additions & 4 deletions config.go → internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package internal

import (
"fmt"
Expand Down Expand Up @@ -56,9 +56,9 @@ func FromEnv() (*Config, error) {
printFailedOnly = true
}

enableRetries := true
if getEnv("ENABLE_RETRIES", "true") == "false" {
enableRetries = false
enableRetries := false
if getEnv("ENABLE_RETRIES", "false") == "true" {
enableRetries = true
}

retryCount, err := strconv.Atoi(getEnv("DEFAULT_RETRY_COUNT", "2"))
Expand Down
2 changes: 1 addition & 1 deletion coordinator.go → internal/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package internal

import (
"sync"
Expand Down
2 changes: 1 addition & 1 deletion dynamic.go → internal/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package internal

import (
"fmt"
Expand Down
3 changes: 2 additions & 1 deletion http.go → internal/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package internal

import (
"bytes"
Expand Down Expand Up @@ -112,6 +112,7 @@ func SendHTTPRequest(config *HTTPRequestConfig) (*http.Response, []byte, error)
if config.MaxRetries > 0 {
client.RetryMax = config.MaxRetries
client.CheckRetry = config.RetryCallback
client.Backoff = retryablehttp.DefaultBackoff
} else {
// Don't retry requests
client.CheckRetry = func(ctx context.Context, resp *http.Response, inErr error) (bool, error) { return false, nil }
Expand Down
2 changes: 1 addition & 1 deletion output.go → internal/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package internal

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion parser.go → internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package internal

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion tester.go → internal/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package internal

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion utils.go → internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package internal

import (
"fmt"
Expand Down
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (

"go.uber.org/zap"
"go.uber.org/zap/zapcore"

ht "github.com/nytimes/httptest/internal"
)

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

// Get and apply config
config, err := FromEnv()
config, err := ht.FromEnv()
if err != nil {
log.Fatalf("error: failed to parse config: %s", err)
}

if err := ApplyConfig(config); err != nil {
if err := ht.ApplyConfig(config); err != nil {
log.Fatalf("error: failed to apply config: %s", err)
}

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

// Parse and run tests
tests, err := ParseAllTestsInDirectory(config.TestDirectory)
tests, err := ht.ParseAllTestsInDirectory(config.TestDirectory)
if err != nil {
log.Fatalf("error: failed to parse tests: %s", err)
}

if !RunTests(tests, config) {
if !ht.RunTests(tests, config) {
os.Exit(1)
}

Expand Down

0 comments on commit 802bed0

Please sign in to comment.