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>
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package image // import "github.com/docker/docker/image" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "fmt" |
|
| 4 | 5 |
"runtime" |
| 5 | 6 |
"testing" |
| 6 | 7 |
|
| ... | ... |
@@ -171,6 +172,20 @@ func TestGetAndSetLastUpdated(t *testing.T) {
|
| 171 | 171 |
assert.Equal(t, updated.IsZero(), false) |
| 172 | 172 |
} |
| 173 | 173 |
|
| 174 |
+func TestStoreLen(t *testing.T) {
|
|
| 175 |
+ store, cleanup := defaultImageStore(t) |
|
| 176 |
+ defer cleanup() |
|
| 177 |
+ |
|
| 178 |
+ expected := 10 |
|
| 179 |
+ for i := 0; i < expected; i++ {
|
|
| 180 |
+ _, err := store.Create([]byte(fmt.Sprintf(`{"comment": "abc%d", "rootfs": {"type": "layers"}}`, i)))
|
|
| 181 |
+ assert.NoError(t, err) |
|
| 182 |
+ } |
|
| 183 |
+ numImages := store.Len() |
|
| 184 |
+ assert.Equal(t, expected, numImages) |
|
| 185 |
+ assert.Equal(t, len(store.Map()), numImages) |
|
| 186 |
+} |
|
| 187 |
+ |
|
| 174 | 188 |
type mockLayerGetReleaser struct{}
|
| 175 | 189 |
|
| 176 | 190 |
func (ls *mockLayerGetReleaser) Get(layer.ChainID) (layer.Layer, error) {
|
| ... | ... |
@@ -263,11 +263,15 @@ func (r *remote) startContainerd() error {
|
| 263 | 263 |
func (r *remote) monitorConnection(monitor *containerd.Client) {
|
| 264 | 264 |
var transientFailureCount = 0 |
| 265 | 265 |
|
| 266 |
- ticker := time.NewTicker(500 * time.Millisecond) |
|
| 267 |
- defer ticker.Stop() |
|
| 268 |
- |
|
| 269 | 266 |
for {
|
| 270 |
- <-ticker.C |
|
| 267 |
+ select {
|
|
| 268 |
+ case <-r.shutdownContext.Done(): |
|
| 269 |
+ r.logger.Info("stopping healthcheck following graceful shutdown")
|
|
| 270 |
+ monitor.Close() |
|
| 271 |
+ return |
|
| 272 |
+ case <-time.After(500 * time.Millisecond): |
|
| 273 |
+ } |
|
| 274 |
+ |
|
| 271 | 275 |
ctx, cancel := context.WithTimeout(r.shutdownContext, healthCheckTimeout) |
| 272 | 276 |
_, err := monitor.IsServing(ctx) |
| 273 | 277 |
cancel() |