Skip to content

Commit

Permalink
Merge #68808
Browse files Browse the repository at this point in the history
68808: kv: deflake and unskip TestMergeQueue/sticky-bit-expiration r=nvanbenschoten a=nvanbenschoten

Fixes #66942.

This was broken by 78078b8, which switched the test from using a `ManualClock` to using a `HybridManualClock`.

Co-authored-by: Nathan VanBenschoten <[email protected]>
  • Loading branch information
craig[bot] and nvanbenschoten committed Aug 13, 2021
2 parents 3928f19 + b333424 commit 7018384
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
11 changes: 8 additions & 3 deletions pkg/kv/kvserver/client_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4422,14 +4422,19 @@ func TestMergeQueue(t *testing.T) {
})

t.Run("sticky-bit-expiration", func(t *testing.T) {
skip.WithIssue(t, 66942, "flakey test")
manualSplitTTL := time.Millisecond * 200
manualSplitTTL := 10 * time.Millisecond
reset(t)
store.MustForceMergeScanAndProcess()
verifyUnmerged(t, store, lhsStartKey, rhsStartKey)

// Pause the clock for the duration of this subtest so that
// the sticky bit does not expire prematurely.
manualClock.Pause()
defer manualClock.Resume()

// Perform manual merge and verify that no merge occurred.
split(t, rhsStartKey.AsRawKey(), tc.Servers[0].Clock().Now().Add(manualSplitTTL.Nanoseconds(), 0) /* expirationTime */)
exp := tc.Servers[0].Clock().Now().Add(manualSplitTTL.Nanoseconds(), 0)
split(t, rhsStartKey.AsRawKey(), exp /* expirationTime */)
clearRange(t, lhsStartKey, rhsEndKey)
store.MustForceMergeScanAndProcess()
verifyUnmerged(t, store, lhsStartKey, rhsStartKey)
Expand Down
8 changes: 8 additions & 0 deletions pkg/util/hlc/hlc.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ func (m *HybridManualClock) Pause() {
m.mu.Unlock()
}

// Resume resumes the hybrid manual clock; the passage of time continues to
// cause clock to tick.
func (m *HybridManualClock) Resume() {
m.mu.Lock()
m.mu.nanosAtPause = 0
m.mu.Unlock()
}

// UnixNano returns the local machine's physical nanosecond
// unix epoch timestamp as a convenience to create a HLC via
// c := hlc.NewClock(hlc.UnixNano, ...).
Expand Down
17 changes: 12 additions & 5 deletions pkg/util/hlc/hlc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,10 @@ func TestHybridManualClock(t *testing.T) {
require.LessOrEqual(t, c.Now().WallTime, UnixNano())
require.LessOrEqual(t, UnixNano(), c.Now().WallTime)

m.Increment(10)
require.LessOrEqual(t, c.Now().WallTime, UnixNano()+10)
require.LessOrEqual(t, UnixNano()+10, c.Now().WallTime)
inc := time.Second.Nanoseconds()
m.Increment(inc)
require.LessOrEqual(t, c.Now().WallTime, UnixNano()+inc)
require.LessOrEqual(t, UnixNano()+inc, c.Now().WallTime)
}

// TestHybridManualClockPause test the Pause() functionality of the
Expand All @@ -391,8 +392,14 @@ func TestHybridManualClockPause(t *testing.T) {
require.Equal(t, now, c.Now().WallTime)
time.Sleep(10 * time.Millisecond)
require.Equal(t, now, c.Now().WallTime)
m.Increment(10)
require.Equal(t, now+10, c.Now().WallTime)
inc := time.Second.Nanoseconds()
m.Increment(inc)
require.Equal(t, now+inc, c.Now().WallTime)
m.Resume()
trueNow := UnixNano()
require.LessOrEqual(t, trueNow+inc, c.Now().WallTime)
time.Sleep(10 * time.Millisecond)
require.Less(t, trueNow+inc, c.Now().WallTime)
}

func TestHLCMonotonicityCheck(t *testing.T) {
Expand Down

0 comments on commit 7018384

Please sign in to comment.