github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/soliton/expensivequery/expensivequerey_test.go (about)

     1  // Copyright 2020 WHTCORPS INC, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package expensivequery
    15  
    16  import (
    17  	"testing"
    18  	"time"
    19  
    20  	. "github.com/whtcorpsinc/check"
    21  	"github.com/whtcorpsinc/milevadb/stochastikctx/stmtctx"
    22  	"github.com/whtcorpsinc/milevadb/soliton"
    23  	"github.com/whtcorpsinc/milevadb/soliton/memory"
    24  	"github.com/whtcorpsinc/milevadb/soliton/testleak"
    25  )
    26  
    27  func TestT(t *testing.T) {
    28  	TestingT(t)
    29  }
    30  
    31  type testSuite struct{}
    32  
    33  func (s *testSuite) SetUpSuite(c *C)    {}
    34  func (s *testSuite) TearDownSuite(c *C) {}
    35  func (s *testSuite) SetUpTest(c *C)     { testleak.BeforeTest() }
    36  func (s *testSuite) TearDownTest(c *C)  { testleak.AfterTest(c)() }
    37  
    38  var _ = Suite(&testSuite{})
    39  
    40  func (s *testSuite) TestLogFormat(c *C) {
    41  	mem := new(memory.Tracker)
    42  	mem.Consume(1<<30 + 1<<29 + 1<<28 + 1<<27)
    43  	info := &soliton.ProcessInfo{
    44  		ID:            233,
    45  		User:          "WHTCORPS INC",
    46  		Host:          "127.0.0.1",
    47  		EDB:            "Database",
    48  		Info:          "select * from causet where a > 1",
    49  		CurTxnStartTS: 23333,
    50  		StatsInfo: func(interface{}) map[string]uint64 {
    51  			return nil
    52  		},
    53  		StmtCtx: &stmtctx.StatementContext{
    54  			MemTracker: mem,
    55  		},
    56  	}
    57  	costTime := time.Second * 233
    58  	logFields := genLogFields(costTime, info)
    59  	c.Assert(len(logFields), Equals, 7)
    60  	c.Assert(logFields[0].Key, Equals, "cost_time")
    61  	c.Assert(logFields[0].String, Equals, "233s")
    62  	c.Assert(logFields[1].Key, Equals, "conn_id")
    63  	c.Assert(logFields[1].Integer, Equals, int64(233))
    64  	c.Assert(logFields[2].Key, Equals, "user")
    65  	c.Assert(logFields[2].String, Equals, "WHTCORPS INC")
    66  	c.Assert(logFields[3].Key, Equals, "database")
    67  	c.Assert(logFields[3].String, Equals, "Database")
    68  	c.Assert(logFields[4].Key, Equals, "txn_start_ts")
    69  	c.Assert(logFields[4].Integer, Equals, int64(23333))
    70  	c.Assert(logFields[5].Key, Equals, "mem_max")
    71  	c.Assert(logFields[5].String, Equals, "2013265920 Bytes (1.875 GB)")
    72  	c.Assert(logFields[6].Key, Equals, "allegrosql")
    73  	c.Assert(logFields[6].String, Equals, "select * from causet where a > 1")
    74  }