Change containerd monitor ticker to sleep

With the ticker this could end up just doing back-to-back checks, which
isn't really what we want here.
Instead use a sleep to ensure we actually sleep for the desired
interval.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2018-03-13 12:21:56 -04:00
parent f6a7763b6f
commit 04a0d6b863
2 changed files with 23 additions and 4 deletions

View file

@ -1,6 +1,7 @@
package image // import "github.com/docker/docker/image" package image // import "github.com/docker/docker/image"
import ( import (
"fmt"
"runtime" "runtime"
"testing" "testing"
@ -171,6 +172,20 @@ func TestGetAndSetLastUpdated(t *testing.T) {
assert.Equal(t, updated.IsZero(), false) assert.Equal(t, updated.IsZero(), false)
} }
func TestStoreLen(t *testing.T) {
store, cleanup := defaultImageStore(t)
defer cleanup()
expected := 10
for i := 0; i < expected; i++ {
_, err := store.Create([]byte(fmt.Sprintf(`{"comment": "abc%d", "rootfs": {"type": "layers"}}`, i)))
assert.NoError(t, err)
}
numImages := store.Len()
assert.Equal(t, expected, numImages)
assert.Equal(t, len(store.Map()), numImages)
}
type mockLayerGetReleaser struct{} type mockLayerGetReleaser struct{}
func (ls *mockLayerGetReleaser) Get(layer.ChainID) (layer.Layer, error) { func (ls *mockLayerGetReleaser) Get(layer.ChainID) (layer.Layer, error) {

View file

@ -263,11 +263,15 @@ func (r *remote) startContainerd() error {
func (r *remote) monitorConnection(monitor *containerd.Client) { func (r *remote) monitorConnection(monitor *containerd.Client) {
var transientFailureCount = 0 var transientFailureCount = 0
ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()
for { for {
<-ticker.C select {
case <-r.shutdownContext.Done():
r.logger.Info("stopping healthcheck following graceful shutdown")
monitor.Close()
return
case <-time.After(500 * time.Millisecond):
}
ctx, cancel := context.WithTimeout(r.shutdownContext, healthCheckTimeout) ctx, cancel := context.WithTimeout(r.shutdownContext, healthCheckTimeout)
_, err := monitor.IsServing(ctx) _, err := monitor.IsServing(ctx)
cancel() cancel()