github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/colexec/serial_unordered_synchronizer_test.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package colexec
    12  
    13  import (
    14  	"context"
    15  	"testing"
    16  
    17  	"github.com/cockroachdb/cockroach/pkg/col/coldata"
    18  	"github.com/cockroachdb/cockroach/pkg/col/coldatatestutils"
    19  	"github.com/cockroachdb/cockroach/pkg/sql/colexecbase"
    20  	"github.com/cockroachdb/cockroach/pkg/sql/types"
    21  	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
    22  	"github.com/cockroachdb/cockroach/pkg/util/randutil"
    23  	"github.com/stretchr/testify/require"
    24  )
    25  
    26  func TestSerialUnorderedSynchronizer(t *testing.T) {
    27  	defer leaktest.AfterTest(t)()
    28  
    29  	ctx := context.Background()
    30  	rng, _ := randutil.NewPseudoRand()
    31  	const numInputs = 3
    32  	const numBatches = 4
    33  
    34  	typs := []*types.T{types.Int}
    35  	inputs := make([]colexecbase.Operator, numInputs)
    36  	for i := range inputs {
    37  		batch := coldatatestutils.RandomBatch(testAllocator, rng, typs, coldata.BatchSize(), 0 /* length */, rng.Float64())
    38  		source := colexecbase.NewRepeatableBatchSource(testAllocator, batch, typs)
    39  		source.ResetBatchesToReturn(numBatches)
    40  		inputs[i] = source
    41  	}
    42  	s := NewSerialUnorderedSynchronizer(inputs, typs)
    43  	resultBatches := 0
    44  	for {
    45  		b := s.Next(ctx)
    46  		if b.Length() == 0 {
    47  			break
    48  		}
    49  		resultBatches++
    50  	}
    51  	require.Equal(t, numInputs*numBatches, resultBatches)
    52  }