github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/colflow/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 colflow_test 12 13 import ( 14 "context" 15 "os" 16 "testing" 17 18 "github.com/cockroachdb/cockroach/pkg/col/coldata" 19 "github.com/cockroachdb/cockroach/pkg/col/coldataext" 20 "github.com/cockroachdb/cockroach/pkg/security" 21 "github.com/cockroachdb/cockroach/pkg/security/securitytest" 22 "github.com/cockroachdb/cockroach/pkg/server" 23 "github.com/cockroachdb/cockroach/pkg/settings/cluster" 24 "github.com/cockroachdb/cockroach/pkg/sql/colmem" 25 "github.com/cockroachdb/cockroach/pkg/sql/execinfra" 26 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 27 "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" 28 "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" 29 "github.com/cockroachdb/cockroach/pkg/util/mon" 30 "github.com/cockroachdb/cockroach/pkg/util/randutil" 31 ) 32 33 //go:generate ../../util/leaktest/add-leaktest.sh *_test.go 34 35 var ( 36 // testAllocator is an Allocator with an unlimited budget for use in tests. 37 testAllocator *colmem.Allocator 38 testColumnFactory coldata.ColumnFactory 39 40 // testMemMonitor and testMemAcc are a test monitor with an unlimited budget 41 // and a memory account bound to it for use in tests. 42 testMemMonitor *mon.BytesMonitor 43 testMemAcc *mon.BoundAccount 44 45 // testDiskMonitor and testDiskmAcc are a test monitor with an unlimited budget 46 // and a disk account bound to it for use in tests. 47 testDiskMonitor *mon.BytesMonitor 48 testDiskAcc *mon.BoundAccount 49 ) 50 51 func TestMain(m *testing.M) { 52 security.SetAssetLoader(securitytest.EmbeddedAssets) 53 randutil.SeedForTests() 54 serverutils.InitTestServerFactory(server.TestServerFactory) 55 serverutils.InitTestClusterFactory(testcluster.TestClusterFactory) 56 os.Exit(func() int { 57 ctx := context.Background() 58 st := cluster.MakeTestingClusterSettings() 59 testMemMonitor = execinfra.NewTestMemMonitor(ctx, st) 60 defer testMemMonitor.Stop(ctx) 61 memAcc := testMemMonitor.MakeBoundAccount() 62 testMemAcc = &memAcc 63 evalCtx := tree.MakeTestingEvalContext(st) 64 testColumnFactory = coldataext.NewExtendedColumnFactory(&evalCtx) 65 testAllocator = colmem.NewAllocator(ctx, testMemAcc, testColumnFactory) 66 defer testMemAcc.Close(ctx) 67 68 testDiskMonitor = execinfra.NewTestDiskMonitor(ctx, cluster.MakeTestingClusterSettings()) 69 defer testDiskMonitor.Stop(ctx) 70 diskAcc := testDiskMonitor.MakeBoundAccount() 71 testDiskAcc = &diskAcc 72 defer testDiskAcc.Close(ctx) 73 74 return m.Run() 75 }()) 76 }