Add a backoff policy for failing pods.

This commit is contained in:
Brendan Burns
2014-10-03 09:59:39 -07:00
parent f9e5477e2b
commit 53304bd024
2 changed files with 134 additions and 4 deletions

View File

@@ -187,7 +187,11 @@ func TestDefaultErrorFunc(t *testing.T) {
server := httptest.NewServer(mux)
factory := ConfigFactory{client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Version()})}
queue := cache.NewFIFO()
errFunc := factory.makeDefaultErrorFunc(queue)
podBackoff := podBackoff{
perPodBackoff: map[string]*backoffEntry{},
clock: &fakeClock{},
}
errFunc := factory.makeDefaultErrorFunc(&podBackoff, queue)
errFunc(testPod, nil)
for {
@@ -276,6 +280,14 @@ func TestMinionEnumerator(t *testing.T) {
}
}
type fakeClock struct {
t time.Time
}
func (f *fakeClock) Now() time.Time {
return f.t
}
func TestBind(t *testing.T) {
table := []struct {
binding *api.Binding
@@ -301,3 +313,55 @@ func TestBind(t *testing.T) {
handler.ValidateRequest(t, "/api/"+testapi.Version()+"/bindings", "POST", &expectedBody)
}
}
func TestBackoff(t *testing.T) {
clock := fakeClock{}
backoff := podBackoff{
perPodBackoff: map[string]*backoffEntry{},
clock: &clock,
}
tests := []struct {
podID string
expectedDuration time.Duration
advanceClock time.Duration
}{
{
podID: "foo",
expectedDuration: 1 * time.Second,
},
{
podID: "foo",
expectedDuration: 2 * time.Second,
},
{
podID: "foo",
expectedDuration: 4 * time.Second,
},
{
podID: "bar",
expectedDuration: 1 * time.Second,
advanceClock: 120 * time.Second,
},
// 'foo' should have been gc'd here.
{
podID: "foo",
expectedDuration: 1 * time.Second,
},
}
for _, test := range tests {
duration := backoff.getBackoff(test.podID)
if duration != test.expectedDuration {
t.Errorf("expected: %s, got %s for %s", test.expectedDuration.String(), duration.String(), test.podID)
}
clock.t = clock.t.Add(test.advanceClock)
backoff.gc()
}
backoff.perPodBackoff["foo"].backoff = 60 * time.Second
duration := backoff.getBackoff("foo")
if duration != 60*time.Second {
t.Errorf("expected: 60, got %s", duration.String())
}
}