github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/colflow/colrpc/main_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 colrpc
    12  
    13  import (
    14  	"context"
    15  	"os"
    16  	"testing"
    17  
    18  	"github.com/cockroachdb/cockroach/pkg/col/coldata"
    19  	"github.com/cockroachdb/cockroach/pkg/settings/cluster"
    20  	"github.com/cockroachdb/cockroach/pkg/sql/colmem"
    21  	"github.com/cockroachdb/cockroach/pkg/sql/execinfra"
    22  	"github.com/cockroachdb/cockroach/pkg/util/mon"
    23  	"github.com/cockroachdb/cockroach/pkg/util/randutil"
    24  )
    25  
    26  var (
    27  	// testAllocator is an Allocator with an unlimited budget for use in tests.
    28  	testAllocator *colmem.Allocator
    29  
    30  	// testMemMonitor and testMemAcc are a test monitor with an unlimited budget
    31  	// and a memory account bound to it for use in tests.
    32  	testMemMonitor *mon.BytesMonitor
    33  	testMemAcc     *mon.BoundAccount
    34  )
    35  
    36  func TestMain(m *testing.M) {
    37  	randutil.SeedForTests()
    38  	os.Exit(func() int {
    39  		ctx := context.Background()
    40  		testMemMonitor = execinfra.NewTestMemMonitor(ctx, cluster.MakeTestingClusterSettings())
    41  		defer testMemMonitor.Stop(ctx)
    42  		memAcc := testMemMonitor.MakeBoundAccount()
    43  		testMemAcc = &memAcc
    44  		testAllocator = colmem.NewAllocator(ctx, testMemAcc, coldata.StandardColumnFactory)
    45  		defer testMemAcc.Close(ctx)
    46  		return m.Run()
    47  	}())
    48  }