improve pleg error msg when it has never been successful

pull/58/head
Seth Jennings 2018-09-24 15:25:28 -05:00
parent 170dcc2ea0
commit 5eab76934b
2 changed files with 12 additions and 1 deletions

View File

@ -132,6 +132,9 @@ func (g *GenericPLEG) Start() {
func (g *GenericPLEG) Healthy() (bool, error) {
relistTime := g.getRelistTime()
if relistTime.IsZero() {
return false, fmt.Errorf("pleg has yet to be successful")
}
elapsed := g.clock.Since(relistTime)
if elapsed > relistThreshold {
return false, fmt.Errorf("pleg was last seen active %v ago; threshold is %v", elapsed, relistThreshold)

View File

@ -346,9 +346,11 @@ func TestRemoveCacheEntry(t *testing.T) {
func TestHealthy(t *testing.T) {
testPleg := newTestGenericPLEG()
// pleg should initially be unhealthy
pleg, _, clock := testPleg.pleg, testPleg.runtime, testPleg.clock
ok, _ := pleg.Healthy()
assert.True(t, ok, "pleg should be healthy")
assert.False(t, ok, "pleg should be unhealthy")
// Advance the clock without any relisting.
clock.Step(time.Minute * 10)
@ -361,6 +363,12 @@ func TestHealthy(t *testing.T) {
clock.Step(time.Minute * 1)
ok, _ = pleg.Healthy()
assert.True(t, ok, "pleg should be healthy")
// Advance by relistThreshold without any relisting. pleg should be unhealthy
// because it has been longer than relistThreshold since a relist occurred.
clock.Step(relistThreshold)
ok, _ = pleg.Healthy()
assert.False(t, ok, "pleg should be unhealthy")
}
func TestRelistWithReinspection(t *testing.T) {