github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/colcontainer/main_test.go (about) 1 // Copyright 2020 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 colcontainer_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/settings/cluster" 21 "github.com/cockroachdb/cockroach/pkg/sql/colmem" 22 "github.com/cockroachdb/cockroach/pkg/sql/execinfra" 23 "github.com/cockroachdb/cockroach/pkg/util/mon" 24 "github.com/cockroachdb/cockroach/pkg/util/randutil" 25 ) 26 27 var ( 28 // testAllocator is a colexec.Allocator with an unlimited budget for use in 29 // tests. 30 testAllocator *colmem.Allocator 31 testColumnFactory coldata.ColumnFactory 32 33 // testMemMonitor and testMemAcc are a test monitor with an unlimited budget 34 // and a memory account bound to it for use in tests. 35 testMemMonitor *mon.BytesMonitor 36 testMemAcc *mon.BoundAccount 37 38 // testDiskMonitor and testDiskmAcc are a test monitor with an unlimited budget 39 // and a disk account bound to it for use in tests. 40 testDiskMonitor *mon.BytesMonitor 41 testDiskAcc *mon.BoundAccount 42 ) 43 44 func TestMain(m *testing.M) { 45 randutil.SeedForTests() 46 os.Exit(func() int { 47 ctx := context.Background() 48 testMemMonitor = execinfra.NewTestMemMonitor(ctx, cluster.MakeTestingClusterSettings()) 49 defer testMemMonitor.Stop(ctx) 50 memAcc := testMemMonitor.MakeBoundAccount() 51 testMemAcc = &memAcc 52 testColumnFactory = coldataext.NewExtendedColumnFactory(nil /* evalCtx */) 53 testAllocator = colmem.NewAllocator(ctx, testMemAcc, testColumnFactory) 54 defer testMemAcc.Close(ctx) 55 56 testDiskMonitor = execinfra.NewTestDiskMonitor(ctx, cluster.MakeTestingClusterSettings()) 57 defer testDiskMonitor.Stop(ctx) 58 diskAcc := testDiskMonitor.MakeBoundAccount() 59 testDiskAcc = &diskAcc 60 defer testDiskAcc.Close(ctx) 61 return m.Run() 62 }()) 63 }