1
0
Fork 0

More HTTP-level unit testing of readyz?commit

master
Philip O'Toole 7 months ago
parent b696f0dea2
commit 53e0666c9e

@ -10,6 +10,7 @@ import (
"net/url"
"os"
"strings"
"sync/atomic"
"testing"
"time"
@ -1046,16 +1047,22 @@ func Test_Readyz(t *testing.T) {
}
m.notReady = true
m.committedFn = func(timeout time.Duration) (uint64, error) {
t.Fatal("committedFn should not have been called")
return 0, nil
}
resp, err = client.Get(host + "/readyz")
if err != nil {
t.Fatalf("failed to make nodes request")
t.Fatalf("failed to make readyz request")
}
if resp.StatusCode != http.StatusServiceUnavailable {
t.Fatalf("failed to get expected StatusServiceUnavailable, got %d", resp.StatusCode)
}
cnt := &atomic.Uint32{}
m.notReady = false
m.committedFn = func(timeout time.Duration) (uint64, error) {
cnt.Store(1)
return 0, fmt.Errorf("timeout")
}
resp, err = client.Get(host + "/readyz?commit")
@ -1065,8 +1072,12 @@ func Test_Readyz(t *testing.T) {
if resp.StatusCode != http.StatusServiceUnavailable {
t.Fatalf("failed to get expected StatusServiceUnavailable, got %d", resp.StatusCode)
}
if cnt.Load() != 1 {
t.Fatalf("failed to call committedFn")
}
m.notReady = false
m.committedFn = func(timeout time.Duration) (uint64, error) {
cnt.Store(2)
return 0, nil
}
resp, err = client.Get(host + "/readyz?commit")
@ -1076,6 +1087,9 @@ func Test_Readyz(t *testing.T) {
if resp.StatusCode != http.StatusOK {
t.Fatalf("failed to get expected StatusOK, got %d", resp.StatusCode)
}
if cnt.Load() != 2 {
t.Fatalf("failed to call committedFn")
}
}
func Test_ForwardingRedirectQuery(t *testing.T) {

Loading…
Cancel
Save