Fix goal recovery
This commit is contained in:
parent
3846556035
commit
996f586bc1
1 changed files with 783 additions and 145 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -48,7 +47,7 @@ func TestRecoveryPolicy(t *testing.T) {
|
|||
{"old blocked", blocked, blocked, "failed", false},
|
||||
{"success", active, active, "completed", false},
|
||||
{"budget", active, "budgetLimited", "failed", false},
|
||||
{"usage", active, "usageLimited", "failed", false},
|
||||
{"usage", active, "usageLimited", "failed", true},
|
||||
{"complete", active, "complete", "failed", false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
|
@ -65,7 +64,7 @@ func TestRecoveryPolicy(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGoalChanges(t *testing.T) {
|
||||
for _, g := range []*goal{nil, testGoal(paused), testGoal("budgetLimited"), testGoal("usageLimited"), testGoal("complete"), {Objective: "Replacement", Status: blocked, CreatedAt: 2}} {
|
||||
for _, g := range []*goal{nil, testGoal(paused), testGoal("budgetLimited"), testGoal("complete"), {Objective: "Replacement", Status: blocked, CreatedAt: 2}} {
|
||||
w := failedWatch()
|
||||
w.schedule(time.Now(), time.Second, time.Minute, func(d time.Duration) time.Duration { return d })
|
||||
w.update(g)
|
||||
|
|
@ -131,46 +130,6 @@ func TestSnapshotReset(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestErrorTypes(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
raw string
|
||||
want bool
|
||||
}{
|
||||
{`"serverOverloaded"`, true},
|
||||
{`"rateLimitExceeded"`, true},
|
||||
{`"internalServerError"`, true},
|
||||
{`{"responseTooManyFailedAttempts":{"httpStatusCode":503}}`, true},
|
||||
{`{"responseStreamDisconnected":{"httpStatusCode":null}}`, true},
|
||||
{`{"httpConnectionFailed":{"httpStatusCode":401}}`, false},
|
||||
{`"unauthorized"`, false},
|
||||
{`"badRequest"`, false},
|
||||
{`"misalignmentPolicyViolation"`, false},
|
||||
{`"usageLimitExceeded"`, false},
|
||||
{`"other"`, false},
|
||||
{`{"futureError":{"httpStatusCode":503}}`, false},
|
||||
{`null`, false},
|
||||
} {
|
||||
var info errorInfo
|
||||
if err := json.Unmarshal([]byte(tc.raw), &info); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if info.retryable() != tc.want {
|
||||
t.Fatalf("%s retryable = %v", tc.raw, info.retryable())
|
||||
}
|
||||
data, err := json.Marshal(info)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var restored errorInfo
|
||||
if err := json.Unmarshal(data, &restored); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if restored.retryable() != tc.want {
|
||||
t.Fatalf("lost error on checkpoint: %s", data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackoff(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
count int
|
||||
|
|
|
|||
Loading…
Reference in a new issue