From a4459f20c568b8b12694b7dc047673cd001f7ea9 Mon Sep 17 00:00:00 2001 From: glorv Date: Mon, 19 Oct 2020 14:03:28 +0800 Subject: [PATCH] wrap time.Sleep in select --- lightning/backend/local.go | 6 +++++- lightning/backend/local_test.go | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lightning/backend/local.go b/lightning/backend/local.go index b65fc6189..b4b264509 100644 --- a/lightning/backend/local.go +++ b/lightning/backend/local.go @@ -1220,7 +1220,11 @@ func (local *local) isIngestRetryable( } log.L().Warn("get region by key return nil, will retry", zap.Reflect("region", region), zap.Int("retry", i)) - time.Sleep(time.Second) + select { + case <-ctx.Done(): + return nil, ctx.Err() + case <-time.After(time.Second): + } } } diff --git a/lightning/backend/local_test.go b/lightning/backend/local_test.go index 6ddfe907e..ec33119f7 100644 --- a/lightning/backend/local_test.go +++ b/lightning/backend/local_test.go @@ -14,9 +14,9 @@ func (s *localSuite) TestNextKey(c *C) { c.Assert(nextKey([]byte{}), DeepEquals, []byte{}) cases := [][]byte{ - []byte{0}, - []byte{255}, - []byte{1, 255}, + {0}, + {255}, + {1, 255}, } for _, b := range cases { next := nextKey(b)