|
@@ -4,6 +4,7 @@ import (
|
|
"bytes"
|
|
"bytes"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"errors"
|
|
"errors"
|
|
|
|
+ "fmt"
|
|
"io"
|
|
"io"
|
|
"net/http"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/http/httptest"
|
|
@@ -30,6 +31,7 @@ func setupRemotePluginServer(t *testing.T) (mux *http.ServeMux, addr string) {
|
|
}
|
|
}
|
|
|
|
|
|
func TestFailedConnection(t *testing.T) {
|
|
func TestFailedConnection(t *testing.T) {
|
|
|
|
+ t.Parallel()
|
|
c, _ := NewClient("tcp://127.0.0.1:1", &tlsconfig.Options{InsecureSkipVerify: true})
|
|
c, _ := NewClient("tcp://127.0.0.1:1", &tlsconfig.Options{InsecureSkipVerify: true})
|
|
_, err := c.callWithRetry("Service.Method", nil, false)
|
|
_, err := c.callWithRetry("Service.Method", nil, false)
|
|
if err == nil {
|
|
if err == nil {
|
|
@@ -38,13 +40,14 @@ func TestFailedConnection(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
func TestFailOnce(t *testing.T) {
|
|
func TestFailOnce(t *testing.T) {
|
|
|
|
+ t.Parallel()
|
|
mux, addr := setupRemotePluginServer(t)
|
|
mux, addr := setupRemotePluginServer(t)
|
|
|
|
|
|
failed := false
|
|
failed := false
|
|
mux.HandleFunc("/Test.FailOnce", func(w http.ResponseWriter, r *http.Request) {
|
|
mux.HandleFunc("/Test.FailOnce", func(w http.ResponseWriter, r *http.Request) {
|
|
if !failed {
|
|
if !failed {
|
|
failed = true
|
|
failed = true
|
|
- panic("Plugin not ready")
|
|
|
|
|
|
+ panic("Plugin not ready (intentional panic for test)")
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
@@ -57,6 +60,7 @@ func TestFailOnce(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
func TestEchoInputOutput(t *testing.T) {
|
|
func TestEchoInputOutput(t *testing.T) {
|
|
|
|
+ t.Parallel()
|
|
mux, addr := setupRemotePluginServer(t)
|
|
mux, addr := setupRemotePluginServer(t)
|
|
|
|
|
|
m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}}
|
|
m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}}
|
|
@@ -87,47 +91,56 @@ func TestEchoInputOutput(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
func TestBackoff(t *testing.T) {
|
|
func TestBackoff(t *testing.T) {
|
|
|
|
+ t.Parallel()
|
|
cases := []struct {
|
|
cases := []struct {
|
|
retries int
|
|
retries int
|
|
expTimeOff time.Duration
|
|
expTimeOff time.Duration
|
|
}{
|
|
}{
|
|
- {0, time.Duration(1)},
|
|
|
|
- {1, time.Duration(2)},
|
|
|
|
- {2, time.Duration(4)},
|
|
|
|
- {4, time.Duration(16)},
|
|
|
|
- {6, time.Duration(30)},
|
|
|
|
- {10, time.Duration(30)},
|
|
|
|
|
|
+ {expTimeOff: time.Duration(1)},
|
|
|
|
+ {retries: 1, expTimeOff: time.Duration(2)},
|
|
|
|
+ {retries: 2, expTimeOff: time.Duration(4)},
|
|
|
|
+ {retries: 4, expTimeOff: time.Duration(16)},
|
|
|
|
+ {retries: 6, expTimeOff: time.Duration(30)},
|
|
|
|
+ {retries: 10, expTimeOff: time.Duration(30)},
|
|
}
|
|
}
|
|
|
|
|
|
- for _, c := range cases {
|
|
|
|
- s := c.expTimeOff * time.Second
|
|
|
|
- if d := backoff(c.retries); d != s {
|
|
|
|
- t.Fatalf("Retry %v, expected %v, was %v\n", c.retries, s, d)
|
|
|
|
- }
|
|
|
|
|
|
+ for _, tc := range cases {
|
|
|
|
+ tc := tc
|
|
|
|
+ t.Run(fmt.Sprintf("retries: %v", tc.retries), func(t *testing.T) {
|
|
|
|
+ s := tc.expTimeOff * time.Second
|
|
|
|
+ if d := backoff(tc.retries); d != s {
|
|
|
|
+ t.Fatalf("Retry %v, expected %v, was %v\n", tc.retries, s, d)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
func TestAbortRetry(t *testing.T) {
|
|
func TestAbortRetry(t *testing.T) {
|
|
|
|
+ t.Parallel()
|
|
cases := []struct {
|
|
cases := []struct {
|
|
timeOff time.Duration
|
|
timeOff time.Duration
|
|
expAbort bool
|
|
expAbort bool
|
|
}{
|
|
}{
|
|
- {time.Duration(1), false},
|
|
|
|
- {time.Duration(2), false},
|
|
|
|
- {time.Duration(10), false},
|
|
|
|
- {time.Duration(30), true},
|
|
|
|
- {time.Duration(40), true},
|
|
|
|
|
|
+ {timeOff: time.Duration(1)},
|
|
|
|
+ {timeOff: time.Duration(2)},
|
|
|
|
+ {timeOff: time.Duration(10)},
|
|
|
|
+ {timeOff: time.Duration(30), expAbort: true},
|
|
|
|
+ {timeOff: time.Duration(40), expAbort: true},
|
|
}
|
|
}
|
|
|
|
|
|
- for _, c := range cases {
|
|
|
|
- s := c.timeOff * time.Second
|
|
|
|
- if a := abort(time.Now(), s); a != c.expAbort {
|
|
|
|
- t.Fatalf("Duration %v, expected %v, was %v\n", c.timeOff, s, a)
|
|
|
|
- }
|
|
|
|
|
|
+ for _, tc := range cases {
|
|
|
|
+ tc := tc
|
|
|
|
+ t.Run(fmt.Sprintf("duration: %v", tc.timeOff), func(t *testing.T) {
|
|
|
|
+ s := tc.timeOff * time.Second
|
|
|
|
+ if a := abort(time.Now(), s); a != tc.expAbort {
|
|
|
|
+ t.Fatalf("Duration %v, expected %v, was %v\n", tc.timeOff, s, a)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
func TestClientScheme(t *testing.T) {
|
|
func TestClientScheme(t *testing.T) {
|
|
|
|
+ t.Parallel()
|
|
cases := map[string]string{
|
|
cases := map[string]string{
|
|
"tcp://127.0.0.1:8080": "http",
|
|
"tcp://127.0.0.1:8080": "http",
|
|
"unix:///usr/local/plugins/foo": "http",
|
|
"unix:///usr/local/plugins/foo": "http",
|
|
@@ -138,7 +151,7 @@ func TestClientScheme(t *testing.T) {
|
|
for addr, scheme := range cases {
|
|
for addr, scheme := range cases {
|
|
u, err := url.Parse(addr)
|
|
u, err := url.Parse(addr)
|
|
if err != nil {
|
|
if err != nil {
|
|
- t.Fatal(err)
|
|
|
|
|
|
+ t.Error(err)
|
|
}
|
|
}
|
|
s := httpScheme(u)
|
|
s := httpScheme(u)
|
|
|
|
|
|
@@ -149,6 +162,7 @@ func TestClientScheme(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
func TestNewClientWithTimeout(t *testing.T) {
|
|
func TestNewClientWithTimeout(t *testing.T) {
|
|
|
|
+ t.Parallel()
|
|
mux, addr := setupRemotePluginServer(t)
|
|
mux, addr := setupRemotePluginServer(t)
|
|
|
|
|
|
m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}}
|
|
m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}}
|
|
@@ -169,6 +183,7 @@ func TestNewClientWithTimeout(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
func TestClientStream(t *testing.T) {
|
|
func TestClientStream(t *testing.T) {
|
|
|
|
+ t.Parallel()
|
|
mux, addr := setupRemotePluginServer(t)
|
|
mux, addr := setupRemotePluginServer(t)
|
|
|
|
|
|
m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}}
|
|
m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}}
|
|
@@ -198,6 +213,7 @@ func TestClientStream(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
func TestClientSendFile(t *testing.T) {
|
|
func TestClientSendFile(t *testing.T) {
|
|
|
|
+ t.Parallel()
|
|
mux, addr := setupRemotePluginServer(t)
|
|
mux, addr := setupRemotePluginServer(t)
|
|
|
|
|
|
m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}}
|
|
m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}}
|
|
@@ -225,6 +241,7 @@ func TestClientSendFile(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
func TestClientWithRequestTimeout(t *testing.T) {
|
|
func TestClientWithRequestTimeout(t *testing.T) {
|
|
|
|
+ t.Parallel()
|
|
type timeoutError interface {
|
|
type timeoutError interface {
|
|
Timeout() bool
|
|
Timeout() bool
|
|
}
|
|
}
|