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:
parent
f6a7763b6f
commit
04a0d6b863
2 changed files with 23 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
package image // import "github.com/docker/docker/image"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
|
@ -171,6 +172,20 @@ func TestGetAndSetLastUpdated(t *testing.T) {
|
|||
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{}
|
||||
|
||||
func (ls *mockLayerGetReleaser) Get(layer.ChainID) (layer.Layer, error) {
|
||||
|
|
|
@ -263,11 +263,15 @@ func (r *remote) startContainerd() error {
|
|||
func (r *remote) monitorConnection(monitor *containerd.Client) {
|
||||
var transientFailureCount = 0
|
||||
|
||||
ticker := time.NewTicker(500 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
|
||||
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)
|
||||
_, err := monitor.IsServing(ctx)
|
||||
cancel()
|
||||
|
|
Loading…
Reference in a new issue