Skip to content

Commit

Permalink
Merge #25433
Browse files Browse the repository at this point in the history
25433: roachtest: make the clock jump and clock monotonic tests subtests r=bdarnell a=petermattis

Fixes #25432

Release note: None

Co-authored-by: Peter Mattis <petermattis@gmail.com>
  • Loading branch information
craig[bot] and petermattis committed May 14, 2018
2 parents 1ca8e6b + 25361e8 commit 92fdda1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 43 deletions.
49 changes: 33 additions & 16 deletions pkg/cmd/roachtest/clock_jump_crash.go
Expand Up @@ -23,11 +23,7 @@ import (
_ "github.com/lib/pq"
)

func runClockJump(t *test, c *cluster, tc clockJumpTestCase) {
ctx := context.Background()

c.l.printf("Running %s\n", tc.name)

func runClockJump(ctx context.Context, t *test, c *cluster, tc clockJumpTestCase) {
// Test with a single node so that the node does not crash due to MaxOffset
// violation when injecting offset
if c.nodes != 1 {
Expand All @@ -38,8 +34,10 @@ func runClockJump(t *test, c *cluster, tc clockJumpTestCase) {
offsetInjector := newOffsetInjector(c)
offsetInjector.deploy(ctx)

t.Status("starting cockroach")
c.Put(ctx, cockroach, "./cockroach", c.All())
if err := c.RunE(ctx, c.Node(1), "test -x ./cockroach"); err != nil {
c.Put(ctx, cockroach, "./cockroach", c.All())
}
c.Wipe(ctx)
c.Start(ctx)

db := c.Conn(ctx, c.nodes)
Expand Down Expand Up @@ -76,9 +74,7 @@ type clockJumpTestCase struct {
aliveAfterOffset bool
}

func registerClockJump(r *registry) {
const numNodes = 1

func makeClockJumpTests() testSpec {
testCases := []clockJumpTestCase{
{
name: "large_forward_enabled",
Expand All @@ -87,8 +83,11 @@ func registerClockJump(r *registry) {
aliveAfterOffset: false,
},
{
name: "small_forward_enabled",
offset: 150 * time.Millisecond,
name: "small_forward_enabled",
// NB: The offset here needs to be small enough such that this jump plus
// the forward jump check interval (125ms) is less than the tolerated
// forward clock jump (250ms).
offset: 100 * time.Millisecond,
jumpCheckEnabled: true,
aliveAfterOffset: true,
},
Expand All @@ -112,15 +111,33 @@ func registerClockJump(r *registry) {
},
}

spec := testSpec{
Name: "jump",
Stable: true, // DO NOT COPY to new tests
}

for i := range testCases {
tc := testCases[i]
r.Add(testSpec{
Name: fmt.Sprintf("clockjump/tc=%s", tc.name),
Nodes: nodes(numNodes),
spec.SubTests = append(spec.SubTests, testSpec{
Name: tc.name,
Stable: true, // DO NOT COPY to new tests
Run: func(ctx context.Context, t *test, c *cluster) {
runClockJump(t, c, tc)
runClockJump(ctx, t, c, tc)
},
})
}

return spec
}

func registerClock(r *registry) {
r.Add(testSpec{
Name: "clock",
Nodes: nodes(1),
Stable: true, // DO NOT COPY to new tests
SubTests: []testSpec{
makeClockJumpTests(),
makeClockMonotonicTests(),
},
})
}
30 changes: 16 additions & 14 deletions pkg/cmd/roachtest/clock_monotonic.go
Expand Up @@ -23,11 +23,7 @@ import (
_ "github.com/lib/pq"
)

func runClockMonotonicity(t *test, c *cluster, tc clockMonotonicityTestCase) {
ctx := context.Background()

c.l.printf("Running %s\n", tc.name)

func runClockMonotonicity(ctx context.Context, t *test, c *cluster, tc clockMonotonicityTestCase) {
// Test with a single node so that the node does not crash due to MaxOffset
// violation when introducing offset
if c.nodes != 1 {
Expand All @@ -38,8 +34,10 @@ func runClockMonotonicity(t *test, c *cluster, tc clockMonotonicityTestCase) {
offsetInjector := newOffsetInjector(c)
offsetInjector.deploy(ctx)

t.Status("starting cockroach")
c.Put(ctx, cockroach, "./cockroach", c.All())
if err := c.RunE(ctx, c.Node(1), "test -x ./cockroach"); err != nil {
c.Put(ctx, cockroach, "./cockroach", c.All())
}
c.Wipe(ctx)
c.Start(ctx)

db := c.Conn(ctx, c.nodes)
Expand Down Expand Up @@ -105,9 +103,7 @@ type clockMonotonicityTestCase struct {
expectIncreasingWallTime bool
}

func registerClockMonotonicity(r *registry) {
const numNodes = 1

func makeClockMonotonicTests() testSpec {
testCases := []clockMonotonicityTestCase{
{
// Without enabling the feature to persist wall time, wall time is
Expand All @@ -125,15 +121,21 @@ func registerClockMonotonicity(r *registry) {
},
}

spec := testSpec{
Name: "monotonic",
Stable: true, // DO NOT COPY to new tests
}

for i := range testCases {
tc := testCases[i]
r.Add(testSpec{
Name: fmt.Sprintf("clockmonotonic/tc=%s", tc.name),
Nodes: nodes(numNodes),
spec.SubTests = append(spec.SubTests, testSpec{
Name: tc.name,
Stable: true, // DO NOT COPY to new tests
Run: func(ctx context.Context, t *test, c *cluster) {
runClockMonotonicity(t, c, tc)
runClockMonotonicity(ctx, t, c, tc)
},
})
}

return spec
}
23 changes: 13 additions & 10 deletions pkg/cmd/roachtest/clock_util.go
Expand Up @@ -45,16 +45,19 @@ type offsetInjector struct {

// deploy installs ntp and downloads / compiles bumptime used to create a clock offset
func (oi *offsetInjector) deploy(ctx context.Context) {
oi.c.Install(ctx, oi.c.All(), "ntp")
oi.c.Install(ctx, oi.c.All(), "gcc")
oi.c.Run(ctx, oi.c.All(), "sudo", "service", "ntp", "stop")
oi.c.Run(ctx,
oi.c.All(),
"curl",
"-kO",
"https://raw.githubusercontent.com/cockroachdb/jepsen/master/cockroachdb/resources/bumptime.c",
)
oi.c.Run(ctx, oi.c.All(), "gcc", "bumptime.c", "-o", "bumptime", "&&", "rm bumptime.c")
if err := oi.c.RunE(ctx, oi.c.All(), "test -x ./bumptime"); err != nil {
oi.c.Install(ctx, oi.c.All(), "ntp")
oi.c.Install(ctx, oi.c.All(), "gcc")
oi.c.Run(ctx, oi.c.All(), "sudo", "service", "ntp", "stop")
oi.c.Run(ctx,
oi.c.All(),
"curl",
"-kO",
"https://raw.githubusercontent.com/cockroachdb/jepsen/master/cockroachdb/resources/bumptime.c",
)
oi.c.Run(ctx, oi.c.All(), "gcc", "bumptime.c", "-o", "bumptime", "&&", "rm bumptime.c")
}

oi.deployed = true
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/cmd/roachtest/registry.go
Expand Up @@ -23,16 +23,15 @@ func registerTests(r *registry) {
registerAllocator(r)
registerBackup(r)
registerCancel(r)
registerClock(r)
registerCopy(r)
registerDebug(r)
registerClockJump(r)
registerClockMonotonicity(r)
registerDecommission(r)
registerDrop(r)
registerHotSpotSplits(r)
registerImportTPCC(r)
registerImportTPCH(r)
registerJepsen(r)
registerHotSpotSplits(r)
registerKV(r)
registerKVScalability(r)
registerKVSplits(r)
Expand Down

0 comments on commit 92fdda1

Please sign in to comment.