Skip to content

Commit

Permalink
feat: rewrite tests to use testify
Browse files Browse the repository at this point in the history
  • Loading branch information
devanbenz committed Dec 16, 2024
1 parent 269405b commit 8058fd3
Showing 1 changed file with 16 additions and 41 deletions.
57 changes: 16 additions & 41 deletions tsdb/engine/tsm1/compact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/influxdata/influxdb/tsdb"
"github.com/influxdata/influxdb/tsdb/engine/tsm1"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -2329,15 +2330,9 @@ func TestDefaultPlanner_PlanOptimize_LargeMultiGeneration(t *testing.T) {
}

tsm, pLen, _ := cp.PlanOptimize()
if exp, got := 1, len(tsm); exp != got {
t.Fatalf("group length mismatch: got %v, exp %v", got, exp)
} else if pLen != int64(len(tsm)) {
t.Fatalf("tsm file plan length mismatch: got %v, exp %v", pLen, exp)
}

if exp, got := len(expFiles), len(tsm[0]); got != exp {
t.Fatalf("tsm file length mismatch: got %v, exp %v", got, exp)
}
require.Equal(t, 1, len(tsm), "group length mismatch: got %d, exp %d", len(tsm), 1)
require.Equal(t, int64(len(tsm)), pLen, "tsm file plan length mismatch: got %d, exp %d", pLen, int64(len(tsm)))
require.Equal(t, len(expFiles), len(tsm[0]), "tsm file length mismatch: got %d, exp %d", len(tsm[0]), len(expFiles))
}

// This test is added to account for a single generation that has a group size
Expand Down Expand Up @@ -2378,17 +2373,10 @@ func TestDefaultPlanner_PlanOptimize_SmallSingleGeneration(t *testing.T) {
}

tsm, pLen, gLen := cp.PlanOptimize()
if exp, got := 1, len(tsm); exp != got {
t.Fatalf("group length mismatch: got %v, exp %v", got, exp)
} else if pLen != int64(len(tsm)) {
t.Fatalf("tsm file plan length mismatch: got %v, exp %v", pLen, exp)
} else if gLen != int64(1) {
t.Fatalf("generation length mismatch: got %v, exp %v", gLen, 1)
}

if exp, got := len(expFiles), len(tsm[0]); got != exp {
t.Fatalf("tsm file length mismatch: got %v, exp %v", got, exp)
}
require.Equal(t, 1, len(tsm), "group length mismatch: got %d, exp %d", len(tsm), 1)
require.Equal(t, int64(len(tsm)), pLen, "tsm file plan length mismatch: got %d, exp %d", pLen, int64(len(expFiles)))
require.Equal(t, int64(1), gLen, "generation length mismatch: got %d, exp %d", gLen, 1)
require.Equal(t, len(expFiles), len(tsm[0]), "tsm file length mismatch: got %d, exp %d", len(tsm[0]), expFiles)
}

// This test is added to account for a single generation that has a group size
Expand Down Expand Up @@ -2426,17 +2414,10 @@ func TestDefaultPlanner_PlanOptimize_SmallSingleGenerationUnderLevel4(t *testing
}

tsm, pLen, gLen := cp.PlanOptimize()
if exp, got := 1, len(tsm); exp != got {
t.Fatalf("group length mismatch: got %v, exp %v", got, exp)
} else if pLen != int64(len(tsm)) {
t.Fatalf("tsm file plan length mismatch: got %v, exp %v", pLen, exp)
} else if gLen != int64(1) {
t.Fatalf("generation length mismatch: got %v, exp %v", gLen, 1)
}

if exp, got := len(expFiles), len(tsm[0]); got != exp {
t.Fatalf("tsm file length mismatch: got %v, exp %v", got, exp)
}
require.Equal(t, 1, len(tsm), "group length mismatch: got %d, exp %d", len(tsm), 1)
require.Equal(t, int64(len(tsm)), pLen, "tsm file plan length mismatch: got %d, exp %d", pLen, int64(len(expFiles)))
require.Equal(t, int64(1), gLen, "generation length mismatch: got %d, exp %d", gLen, 1)
require.Equal(t, len(expFiles), len(tsm[0]), "tsm file length mismatch: got %d, exp %d", len(tsm[0]), expFiles)
}

// This test is added to account for a single generation that has a group size
Expand Down Expand Up @@ -2474,11 +2455,8 @@ func TestDefaultPlanner_FullyCompacted_SmallSingleGeneration(t *testing.T) {

compacted, reason := cp.FullyCompacted()
reasonExp := "not fully compacted and not idle because group size under 2 GB and more then single file"
if exp, got := false, compacted; exp != got {
t.Fatalf("group length mismatch: got %v, exp %v", got, exp)
} else if reason != reasonExp {
t.Fatalf("tsm file plan length mismatch: got %v, exp %v", reason, reasonExp)
}
require.Equal(t, reason, reasonExp)
require.Equal(t, false, compacted)
}

// This test is added to account for halting state after
Expand All @@ -2504,11 +2482,8 @@ func TestDefaultPlanner_FullyCompacted_SmallSingleGeneration_Halt(t *testing.T)

compacted, reason := cp.FullyCompacted()
reasonExp := ""
if exp, got := true, compacted; exp != got {
t.Fatalf("group length mismatch: got %v, exp %v", got, exp)
} else if reason != reasonExp {
t.Fatalf("tsm file plan length mismatch: got %v, exp %v", reason, reasonExp)
}
require.Equal(t, reason, reasonExp)
require.Equal(t, true, compacted)
}

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

0 comments on commit 8058fd3

Please sign in to comment.