Commit 7276abc1 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

test: upgrade retryablehttp client and fix its unit test

parent 82d4a148
...@@ -132,6 +132,14 @@ ...@@ -132,6 +132,14 @@
pruneopts = "UT" pruneopts = "UT"
revision = "d5fe4b57a186c716b0e00b8c301cbd9b4182694d" revision = "d5fe4b57a186c716b0e00b8c301cbd9b4182694d"
[[projects]]
digest = "1:cf6b61e1b4c26b0c7526cee4a0cee6d8302b17798af4b2a56a90eedac0aef11a"
name = "github.com/hashicorp/go-hclog"
packages = ["."]
pruneopts = "UT"
revision = "5ccdce08c75b6c7b37af61159f13f6a4f5e2e928"
version = "v0.9.2"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:e5048c5da80697be2fcdecc944e29d2999e01fd7f48b643168443209779f3463" digest = "1:e5048c5da80697be2fcdecc944e29d2999e01fd7f48b643168443209779f3463"
...@@ -141,12 +149,12 @@ ...@@ -141,12 +149,12 @@
revision = "b7773ae218740a7be65057fc60b366a49b538a44" revision = "b7773ae218740a7be65057fc60b366a49b538a44"
[[projects]] [[projects]]
branch = "master" digest = "1:bc4393e7d030ef4a548d9643997e2ae9064ed93d7ed140569b27336ee3b77464"
digest = "1:27d0d41550b480f5a217f6ad9f82491248d092e9cea775845d8784e0fc7c7d1b"
name = "github.com/hashicorp/go-retryablehttp" name = "github.com/hashicorp/go-retryablehttp"
packages = ["."] packages = ["."]
pruneopts = "UT" pruneopts = "UT"
revision = "3b087ef2d313afe6c55b2f511d20db04ca767075" revision = "a83ad44d6a5fc343d7c4babf601092b3c189f402"
version = "v0.6.2"
[[projects]] [[projects]]
digest = "1:ea40c24cdbacd054a6ae9de03e62c5f252479b96c716375aace5c120d68647c8" digest = "1:ea40c24cdbacd054a6ae9de03e62c5f252479b96c716375aace5c120d68647c8"
...@@ -472,6 +480,7 @@ ...@@ -472,6 +480,7 @@
"github.com/go-chi/chi/middleware", "github.com/go-chi/chi/middleware",
"github.com/go-chi/cors", "github.com/go-chi/cors",
"github.com/go-errors/errors", "github.com/go-errors/errors",
"github.com/hashicorp/go-cleanhttp",
"github.com/hashicorp/go-retryablehttp", "github.com/hashicorp/go-retryablehttp",
"github.com/jasonlvhit/gocron", "github.com/jasonlvhit/gocron",
"github.com/mdp/qrterminal", "github.com/mdp/qrterminal",
......
...@@ -48,24 +48,22 @@ func StopSchemeManagerHttpServer() { ...@@ -48,24 +48,22 @@ func StopSchemeManagerHttpServer() {
func StartBadHttpServer(count int, timeout time.Duration, success string) { func StartBadHttpServer(count int, timeout time.Duration, success string) {
badServer = &http.Server{Addr: ":48682", Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { badServer = &http.Server{Addr: ":48682", Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if badServerCount >= count { if badServerCount >= count {
fmt.Fprintln(w, success) _, _ = fmt.Fprintln(w, success)
return return
} } else {
badServerCount++ badServerCount++
if badServerCount == 1 {
time.Sleep(timeout) time.Sleep(timeout)
} }
w.WriteHeader(500)
})} })}
go func() { go func() {
badServer.ListenAndServe() _ = badServer.ListenAndServe()
}() }()
time.Sleep(100 * time.Millisecond) // Give server time to start time.Sleep(100 * time.Millisecond) // Give server time to start
} }
func StopBadHttpServer() { func StopBadHttpServer() {
badServer.Close() _ = badServer.Close()
} }
// FindTestdataFolder finds the "testdata" folder which is in . or .. // FindTestdataFolder finds the "testdata" folder which is in . or ..
......
...@@ -46,7 +46,7 @@ func TestConfigurationAutocopy(t *testing.T) { ...@@ -46,7 +46,7 @@ func TestConfigurationAutocopy(t *testing.T) {
func TestParseInvalidIrmaConfiguration(t *testing.T) { func TestParseInvalidIrmaConfiguration(t *testing.T) {
// The description.xml of the scheme manager under this folder has been edited // The description.xml of the scheme manager under this folder has been edited
// to invalidate the scheme manager signature // to invalidate the scheme manager signature
conf, err := NewConfigurationReadOnly(filepath.Join("testdata","irma_configuration_invalid")) conf, err := NewConfigurationReadOnly(filepath.Join("testdata", "irma_configuration_invalid"))
require.NoError(t, err) require.NoError(t, err)
// Parsing it should return a SchemeManagerError // Parsing it should return a SchemeManagerError
...@@ -64,7 +64,7 @@ func TestParseInvalidIrmaConfiguration(t *testing.T) { ...@@ -64,7 +64,7 @@ func TestParseInvalidIrmaConfiguration(t *testing.T) {
} }
func TestRetryHTTPRequest(t *testing.T) { func TestRetryHTTPRequest(t *testing.T) {
test.StartBadHttpServer(3, 1*time.Second, "42") test.StartBadHttpServer(2, 1*time.Second, "42")
defer test.StopBadHttpServer() defer test.StopBadHttpServer()
transport := NewHTTPTransport("http://localhost:48682") transport := NewHTTPTransport("http://localhost:48682")
...@@ -82,7 +82,7 @@ func TestInvalidIrmaConfigurationRestoreFromRemote(t *testing.T) { ...@@ -82,7 +82,7 @@ func TestInvalidIrmaConfigurationRestoreFromRemote(t *testing.T) {
defer test.ClearTestStorage(t) defer test.ClearTestStorage(t)
conf, err := NewConfigurationFromAssets(filepath.Join("testdata", "storage", "test", "irma_configuration"), conf, err := NewConfigurationFromAssets(filepath.Join("testdata", "storage", "test", "irma_configuration"),
filepath.Join("testdata","irma_configuration_invalid")) filepath.Join("testdata", "irma_configuration_invalid"))
require.NoError(t, err) require.NoError(t, err)
err = conf.ParseOrRestoreFolder() err = conf.ParseOrRestoreFolder()
......
...@@ -2,6 +2,7 @@ package irma ...@@ -2,6 +2,7 @@ package irma
import ( import (
"bytes" "bytes"
"context"
"crypto/sha256" "crypto/sha256"
"encoding/json" "encoding/json"
"io" "io"
...@@ -72,7 +73,7 @@ func NewHTTPTransport(serverURL string) *HTTPTransport { ...@@ -72,7 +73,7 @@ func NewHTTPTransport(serverURL string) *HTTPTransport {
RetryWaitMax: 200 * time.Millisecond, RetryWaitMax: 200 * time.Millisecond,
RetryMax: 2, RetryMax: 2,
Backoff: retryablehttp.DefaultBackoff, Backoff: retryablehttp.DefaultBackoff,
CheckRetry: func(resp *http.Response, err error) (bool, error) { CheckRetry: func(ctx context.Context, resp *http.Response, err error) (bool, error) {
// Don't retry on 5xx (which retryablehttp does by default) // Don't retry on 5xx (which retryablehttp does by default)
return err != nil || resp.StatusCode == 0, err return err != nil || resp.StatusCode == 0, err
}, },
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment