Skip to content

Commit

Permalink
[tests] test setups exported to allow us to use it from other packages (
Browse files Browse the repository at this point in the history
  • Loading branch information
gediminasgu authored Jan 21, 2021
1 parent 6c4ed00 commit 9387826
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 96 deletions.
12 changes: 6 additions & 6 deletions src/dbnode/integration/cluster_add_one_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ func testClusterAddOneNode(t *testing.T, verifyCommitlogCanBootstrapAfterNodeJoi
topoOpts := topology.NewDynamicOptions().
SetConfigServiceClient(fake.NewM3ClusterClient(svcs, nil))
topoInit := topology.NewDynamicInitializer(topoOpts)
setupOpts := []bootstrappableTestSetupOptions{
setupOpts := []BootstrappableTestSetupOptions{
{
disablePeersBootstrapper: true,
topologyInitializer: topoInit,
DisablePeersBootstrapper: true,
TopologyInitializer: topoInit,
},
{
disablePeersBootstrapper: false,
topologyInitializer: topoInit,
DisablePeersBootstrapper: false,
TopologyInitializer: topoInit,
},
}
setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

// Write test data for first node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ func TestCommitLogBootstrapUnownedShard(t *testing.T) {
opts := NewTestOptions(t).
SetNamespaces([]namespace.Metadata{ns1}).
SetNumShards(numShards)
setupOpts := []bootstrappableTestSetupOptions{
{disablePeersBootstrapper: true, topologyInitializer: topoInit},
{disablePeersBootstrapper: true, topologyInitializer: topoInit},
setupOpts := []BootstrappableTestSetupOptions{
{DisablePeersBootstrapper: true, TopologyInitializer: topoInit},
{DisablePeersBootstrapper: true, TopologyInitializer: topoInit},
}

setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

// Only set this up for the first setup because we're only writing commit
Expand Down
58 changes: 35 additions & 23 deletions src/dbnode/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func newMultiAddrAdminClient(
topologyInitializer topology.Initializer,
origin topology.Host,
instrumentOpts instrument.Options,
customOpts ...client.CustomAdminOption,
) client.AdminClient {
if adminOpts == nil {
adminOpts = client.NewAdminOptions()
Expand All @@ -105,22 +106,28 @@ func newMultiAddrAdminClient(
SetTopologyInitializer(topologyInitializer).
SetClusterConnectTimeout(time.Second).(client.AdminOptions)

for _, o := range customOpts {
adminOpts = o(adminOpts)
}

adminClient, err := client.NewAdminClient(adminOpts)
require.NoError(t, err)

return adminClient
}

type bootstrappableTestSetupOptions struct {
finalBootstrapper string
bootstrapBlocksBatchSize int
bootstrapBlocksConcurrency int
bootstrapConsistencyLevel topology.ReadConsistencyLevel
topologyInitializer topology.Initializer
testStatsReporter xmetrics.TestStatsReporter
disablePeersBootstrapper bool
useTChannelClientForWriting bool
enableRepairs bool
// BootstrappableTestSetupOptions defines options for test setups.
type BootstrappableTestSetupOptions struct {
FinalBootstrapper string
BootstrapBlocksBatchSize int
BootstrapBlocksConcurrency int
BootstrapConsistencyLevel topology.ReadConsistencyLevel
TopologyInitializer topology.Initializer
TestStatsReporter xmetrics.TestStatsReporter
DisablePeersBootstrapper bool
UseTChannelClientForWriting bool
EnableRepairs bool
AdminClientCustomOpts []client.CustomAdminOption
}

type closeFn func()
Expand All @@ -135,10 +142,11 @@ func newDefaulTestResultOptions(
SetSeriesCachePolicy(storageOpts.SeriesCachePolicy())
}

func newDefaultBootstrappableTestSetups(
// NewDefaultBootstrappableTestSetups creates dbnode test setups.
func NewDefaultBootstrappableTestSetups( // nolint:gocyclo
t *testing.T,
opts TestOptions,
setupOpts []bootstrappableTestSetupOptions,
setupOpts []BootstrappableTestSetupOptions,
) (testSetups, closeFn) {
var (
replicas = len(setupOpts)
Expand All @@ -158,17 +166,18 @@ func newDefaultBootstrappableTestSetups(
for i := 0; i < replicas; i++ {
var (
instance = i
usingPeersBootstrapper = !setupOpts[i].disablePeersBootstrapper
finalBootstrapperToUse = setupOpts[i].finalBootstrapper
useTChannelClientForWriting = setupOpts[i].useTChannelClientForWriting
bootstrapBlocksBatchSize = setupOpts[i].bootstrapBlocksBatchSize
bootstrapBlocksConcurrency = setupOpts[i].bootstrapBlocksConcurrency
bootstrapConsistencyLevel = setupOpts[i].bootstrapConsistencyLevel
topologyInitializer = setupOpts[i].topologyInitializer
testStatsReporter = setupOpts[i].testStatsReporter
enableRepairs = setupOpts[i].enableRepairs
usingPeersBootstrapper = !setupOpts[i].DisablePeersBootstrapper
finalBootstrapperToUse = setupOpts[i].FinalBootstrapper
useTChannelClientForWriting = setupOpts[i].UseTChannelClientForWriting
bootstrapBlocksBatchSize = setupOpts[i].BootstrapBlocksBatchSize
bootstrapBlocksConcurrency = setupOpts[i].BootstrapBlocksConcurrency
bootstrapConsistencyLevel = setupOpts[i].BootstrapConsistencyLevel
topologyInitializer = setupOpts[i].TopologyInitializer
testStatsReporter = setupOpts[i].TestStatsReporter
enableRepairs = setupOpts[i].EnableRepairs
origin topology.Host
instanceOpts = newMultiAddrTestOptions(opts, instance)
adminClientCustomOpts = setupOpts[i].AdminClientCustomOpts
)

if finalBootstrapperToUse == "" {
Expand Down Expand Up @@ -211,7 +220,7 @@ func newDefaultBootstrappableTestSetups(
// claim manager instances after the initial node.
persistfs.ResetIndexClaimsManagersUnsafe()
}
setup, err := NewTestSetup(t, instanceOpts, nil)
setup, err := NewTestSetup(t, instanceOpts, nil, opts.StorageOptsFn())
require.NoError(t, err)
topologyInitializer = setup.TopologyInitializer()

Expand Down Expand Up @@ -260,8 +269,11 @@ func newDefaultBootstrappableTestSetups(
adminOpts = adminOpts.SetFetchSeriesBlocksBatchConcurrency(bootstrapBlocksConcurrency)
}
adminOpts = adminOpts.SetStreamBlocksRetrier(retrier)

adminClient := newMultiAddrAdminClient(
t, adminOpts, topologyInitializer, origin, instrumentOpts)
t, adminOpts, topologyInitializer, origin, instrumentOpts, adminClientCustomOpts...)
setup.SetStorageOpts(setup.StorageOpts().SetAdminClient(adminClient))

storageIdxOpts := setup.StorageOpts().IndexOptions()
fsOpts := setup.StorageOpts().CommitLogOptions().FilesystemOptions()
if usingPeersBootstrapper {
Expand Down
17 changes: 17 additions & 0 deletions src/dbnode/integration/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ type TestOptions interface {

// ReportInterval returns the time between reporting metrics within the system.
ReportInterval() time.Duration

// SetStorageOptsFn sets the StorageOpts modifier.
SetStorageOptsFn(StorageOption) TestOptions

// StorageOptsFn returns the StorageOpts modifier.
StorageOptsFn() StorageOption
}

type options struct {
Expand Down Expand Up @@ -327,6 +333,7 @@ type options struct {
assertEqual assertTestDataEqual
nowFn func() time.Time
reportInterval time.Duration
storageOptsFn StorageOption
}

// NewTestOptions returns a new set of integration test options.
Expand Down Expand Up @@ -676,3 +683,13 @@ func (o *options) SetReportInterval(value time.Duration) TestOptions {
func (o *options) ReportInterval() time.Duration {
return o.reportInterval
}

func (o *options) SetStorageOptsFn(storageOptsFn StorageOption) TestOptions {
opts := *o
opts.storageOptsFn = storageOptsFn
return &opts
}

func (o *options) StorageOptsFn() StorageOption {
return o.storageOptsFn
}
12 changes: 6 additions & 6 deletions src/dbnode/integration/peers_bootstrap_high_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ func testPeersBootstrapHighConcurrency(

batchSize := 16
concurrency := 64
setupOpts := []bootstrappableTestSetupOptions{
setupOpts := []BootstrappableTestSetupOptions{
{
disablePeersBootstrapper: true,
DisablePeersBootstrapper: true,
},
{
disablePeersBootstrapper: false,
bootstrapBlocksBatchSize: batchSize,
bootstrapBlocksConcurrency: concurrency,
DisablePeersBootstrapper: false,
BootstrapBlocksBatchSize: batchSize,
BootstrapBlocksConcurrency: concurrency,
},
}
setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

// Write test data for first node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func TestPeersBootstrapIndexAggregateQuery(t *testing.T) {
SetUseTChannelClientForWriting(true).
SetUseTChannelClientForReading(true)

setupOpts := []bootstrappableTestSetupOptions{
{disablePeersBootstrapper: true},
{disablePeersBootstrapper: false},
setupOpts := []BootstrappableTestSetupOptions{
{DisablePeersBootstrapper: true},
{DisablePeersBootstrapper: false},
}
setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

// Write test data for first node
Expand Down
8 changes: 4 additions & 4 deletions src/dbnode/integration/peers_bootstrap_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func TestPeersBootstrapIndexWithIndexingEnabled(t *testing.T) {
SetUseTChannelClientForWriting(true).
SetUseTChannelClientForReading(true)

setupOpts := []bootstrappableTestSetupOptions{
{disablePeersBootstrapper: true},
{disablePeersBootstrapper: false},
setupOpts := []BootstrappableTestSetupOptions{
{DisablePeersBootstrapper: true},
{DisablePeersBootstrapper: false},
}
setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

// Write test data for first node
Expand Down
14 changes: 7 additions & 7 deletions src/dbnode/integration/peers_bootstrap_merge_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ func testPeersBootstrapMergeLocal(t *testing.T, setTestOpts setTestOptions, upda
// Enable useTchannelClientForWriting because this test relies upon being
// able to write data to a single node, and the M3DB client does not support
// that, but we can accomplish it by using an individual nodes TChannel endpoints.
setupOpts = []bootstrappableTestSetupOptions{
setupOpts = []BootstrappableTestSetupOptions{
{
disablePeersBootstrapper: true,
useTChannelClientForWriting: true,
DisablePeersBootstrapper: true,
UseTChannelClientForWriting: true,
},
{
disablePeersBootstrapper: false,
useTChannelClientForWriting: true,
testStatsReporter: reporter,
DisablePeersBootstrapper: false,
UseTChannelClientForWriting: true,
TestStatsReporter: reporter,
},
}
)
Expand All @@ -91,7 +91,7 @@ func testPeersBootstrapMergeLocal(t *testing.T, setTestOpts setTestOptions, upda
namesp = opts.Namespaces()[0]
}

setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

// Write test data for first node, ensure to overflow past
Expand Down
10 changes: 5 additions & 5 deletions src/dbnode/integration/peers_bootstrap_merge_peer_blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ func testPeersBootstrapMergePeerBlocks(t *testing.T, setTestOpts setTestOptions,
opts = setTestOpts(t, opts)
namesp = opts.Namespaces()[0]
}
setupOpts := []bootstrappableTestSetupOptions{
{disablePeersBootstrapper: true},
{disablePeersBootstrapper: true},
{disablePeersBootstrapper: false},
setupOpts := []BootstrappableTestSetupOptions{
{DisablePeersBootstrapper: true},
{DisablePeersBootstrapper: true},
{DisablePeersBootstrapper: false},
}
setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

// Write test data alternating missing data for left/right nodes
Expand Down
10 changes: 5 additions & 5 deletions src/dbnode/integration/peers_bootstrap_node_down_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ func TestPeersBootstrapNodeDown(t *testing.T) {
SetUseTChannelClientForWriting(true).
SetUseTChannelClientForReading(true)

setupOpts := []bootstrappableTestSetupOptions{
{disablePeersBootstrapper: true},
{disablePeersBootstrapper: true},
{disablePeersBootstrapper: false},
setupOpts := []BootstrappableTestSetupOptions{
{DisablePeersBootstrapper: true},
{DisablePeersBootstrapper: true},
{DisablePeersBootstrapper: false},
}
setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

// Write test data for first node
Expand Down
12 changes: 6 additions & 6 deletions src/dbnode/integration/peers_bootstrap_none_available_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ func TestPeersBootstrapNoneAvailable(t *testing.T) {
SetShardSet(shardSet)
topoInit := topology.NewStaticInitializer(topoOpts)

setupOpts := []bootstrappableTestSetupOptions{
setupOpts := []BootstrappableTestSetupOptions{
{
disablePeersBootstrapper: false,
topologyInitializer: topoInit,
DisablePeersBootstrapper: false,
TopologyInitializer: topoInit,
},
{
disablePeersBootstrapper: false,
topologyInitializer: topoInit,
DisablePeersBootstrapper: false,
TopologyInitializer: topoInit,
},
}
setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

serversAreUp := &sync.WaitGroup{}
Expand Down
10 changes: 5 additions & 5 deletions src/dbnode/integration/peers_bootstrap_select_best_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ func TestPeersBootstrapSelectBest(t *testing.T) {
SetUseTChannelClientForWriting(true).
SetUseTChannelClientForReading(true)

setupOpts := []bootstrappableTestSetupOptions{
{disablePeersBootstrapper: true},
{disablePeersBootstrapper: true},
{disablePeersBootstrapper: false},
setupOpts := []BootstrappableTestSetupOptions{
{DisablePeersBootstrapper: true},
{DisablePeersBootstrapper: true},
{DisablePeersBootstrapper: false},
}
setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

// Write test data alternating missing data for left/right nodes
Expand Down
8 changes: 4 additions & 4 deletions src/dbnode/integration/peers_bootstrap_simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func testPeersBootstrapSimple(t *testing.T, setTestOpts setTestOptions, updateIn
namesp = opts.Namespaces()[0]
}

setupOpts := []bootstrappableTestSetupOptions{
{disablePeersBootstrapper: true},
{disablePeersBootstrapper: false},
setupOpts := []BootstrappableTestSetupOptions{
{DisablePeersBootstrapper: true},
{DisablePeersBootstrapper: false},
}
setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

// Write test data for first node
Expand Down
6 changes: 3 additions & 3 deletions src/dbnode/integration/peers_bootstrap_single_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ func TestPeersBootstrapSingleNode(t *testing.T) {
SetUseTChannelClientForWriting(true).
SetUseTChannelClientForReading(true)

setupOpts := []bootstrappableTestSetupOptions{
{disablePeersBootstrapper: false},
setupOpts := []BootstrappableTestSetupOptions{
{DisablePeersBootstrapper: false},
}
setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

// Write test data
Expand Down
10 changes: 5 additions & 5 deletions src/dbnode/integration/repair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ func testRepair(
SetUseTChannelClientForWriting(true).
SetUseTChannelClientForReading(true)

setupOpts := []bootstrappableTestSetupOptions{
{disablePeersBootstrapper: true, enableRepairs: true},
{disablePeersBootstrapper: true, enableRepairs: true},
{disablePeersBootstrapper: true, enableRepairs: true},
setupOpts := []BootstrappableTestSetupOptions{
{DisablePeersBootstrapper: true, EnableRepairs: true},
{DisablePeersBootstrapper: true, EnableRepairs: true},
{DisablePeersBootstrapper: true, EnableRepairs: true},
}
setups, closeFn := newDefaultBootstrappableTestSetups(t, opts, setupOpts)
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts)
defer closeFn()

// Ensure that the current time is set such that the previous block is flushable.
Expand Down
Loading

0 comments on commit 9387826

Please sign in to comment.