github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/allegrosql/select_result_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 allegrosql
    15  
    16  import (
    17  	"context"
    18  
    19  	. "github.com/whtcorpsinc/check"
    20  	"github.com/whtcorpsinc/milevadb/stochastikctx/stmtctx"
    21  	"github.com/whtcorpsinc/milevadb/causetstore/einsteindb"
    22  	"github.com/whtcorpsinc/milevadb/soliton/execdetails"
    23  	"github.com/whtcorpsinc/milevadb/soliton/mock"
    24  	"github.com/whtcorpsinc/fidelpb/go-fidelpb"
    25  )
    26  
    27  func (s *testSuite) TestUFIDelateCopRuntimeStats(c *C) {
    28  	ctx := mock.NewContext()
    29  	ctx.GetStochastikVars().StmtCtx = new(stmtctx.StatementContext)
    30  	sr := selectResult{ctx: ctx}
    31  	c.Assert(ctx.GetStochastikVars().StmtCtx.RuntimeStatsDefCausl, IsNil)
    32  	sr.rootCausetID = 1234
    33  	sr.uFIDelateCopRuntimeStats(context.Background(), &einsteindb.CopRuntimeStats{InterDircDetails: execdetails.InterDircDetails{CalleeAddress: "a"}}, 0)
    34  
    35  	ctx.GetStochastikVars().StmtCtx.RuntimeStatsDefCausl = execdetails.NewRuntimeStatsDefCausl()
    36  	t := uint64(1)
    37  	sr.selectResp = &fidelpb.SelectResponse{
    38  		InterDircutionSummaries: []*fidelpb.InterlockingDirectorateInterDircutionSummary{
    39  			{TimeProcessedNs: &t, NumProducedRows: &t, NumIterations: &t},
    40  		},
    41  	}
    42  	c.Assert(len(sr.selectResp.GetInterDircutionSummaries()) != len(sr.copCausetIDs), IsTrue)
    43  	sr.uFIDelateCopRuntimeStats(context.Background(), &einsteindb.CopRuntimeStats{InterDircDetails: execdetails.InterDircDetails{CalleeAddress: "callee"}}, 0)
    44  	c.Assert(ctx.GetStochastikVars().StmtCtx.RuntimeStatsDefCausl.ExistsCopStats(1234), IsFalse)
    45  
    46  	sr.copCausetIDs = []int{sr.rootCausetID}
    47  	c.Assert(ctx.GetStochastikVars().StmtCtx.RuntimeStatsDefCausl, NotNil)
    48  	c.Assert(len(sr.selectResp.GetInterDircutionSummaries()), Equals, len(sr.copCausetIDs))
    49  	sr.uFIDelateCopRuntimeStats(context.Background(), &einsteindb.CopRuntimeStats{InterDircDetails: execdetails.InterDircDetails{CalleeAddress: "callee"}}, 0)
    50  	c.Assert(ctx.GetStochastikVars().StmtCtx.RuntimeStatsDefCausl.GetCopStats(1234).String(), Equals, "time:1ns, loops:1")
    51  }