1111// See the License for the specific language governing permissions and
1212// limitations under the License.
1313
14- package stmtctx
14+ package stmtctx_test
1515
1616import (
1717 "fmt"
1818 "testing"
1919 "time"
2020
21+ . "github.com/pingcap/check"
22+ "github.com/pingcap/tidb/sessionctx/stmtctx"
2123 "github.com/pingcap/tidb/util/execdetails"
2224)
2325
24- func TestCopTasksDetails (t * testing.T ) {
25- ctx := new (StatementContext )
26+ func TestT (t * testing.T ) {
27+ TestingT (t )
28+ }
29+
30+ type stmtctxSuit struct {}
31+
32+ var _ = Suite (& stmtctxSuit {})
33+
34+ func (s * stmtctxSuit ) TestCopTasksDetails (c * C ) {
35+ ctx := new (stmtctx.StatementContext )
2636 for i := 0 ; i < 100 ; i ++ {
2737 d := & execdetails.ExecDetails {
2838 CalleeAddress : fmt .Sprintf ("%v" , i + 1 ),
@@ -31,20 +41,42 @@ func TestCopTasksDetails(t *testing.T) {
3141 }
3242 ctx .MergeExecDetails (d , nil )
3343 }
34- c := ctx .CopTasksDetails ()
35- if c .NumCopTasks != 100 ||
36- c .AvgProcessTime != time .Second * 101 / 2 ||
37- c .P90ProcessTime != time .Second * 91 ||
38- c .MaxProcessTime != time .Second * 100 ||
39- c .MaxProcessAddress != "100" ||
40- c .AvgWaitTime != time .Millisecond * 101 / 2 ||
41- c .P90WaitTime != time .Millisecond * 91 ||
42- c .MaxWaitTime != time .Millisecond * 100 ||
43- c .MaxWaitAddress != "100" {
44- t .Fatal (c )
44+ d := ctx .CopTasksDetails ()
45+ c .Assert (d .NumCopTasks , Equals , 100 )
46+ c .Assert (d .AvgProcessTime , Equals , time .Second * 101 / 2 )
47+ c .Assert (d .P90ProcessTime , Equals , time .Second * 91 )
48+ c .Assert (d .MaxProcessTime , Equals , time .Second * 100 )
49+ c .Assert (d .MaxProcessAddress , Equals , "100" )
50+ c .Assert (d .AvgWaitTime , Equals , time .Millisecond * 101 / 2 )
51+ c .Assert (d .P90WaitTime , Equals , time .Millisecond * 91 )
52+ c .Assert (d .MaxWaitTime , Equals , time .Millisecond * 100 )
53+ c .Assert (d .MaxWaitAddress , Equals , "100" )
54+ fields := d .ToZapFields ()
55+ c .Assert (len (fields ), Equals , 9 )
56+ }
57+
58+ func (s * stmtctxSuit ) TestStatementContextPushDownFLags (c * C ) {
59+ testCases := []struct {
60+ in * stmtctx.StatementContext
61+ out uint64
62+ }{
63+ {& stmtctx.StatementContext {InInsertStmt : true }, 8 },
64+ {& stmtctx.StatementContext {InUpdateStmt : true }, 16 },
65+ {& stmtctx.StatementContext {InDeleteStmt : true }, 16 },
66+ {& stmtctx.StatementContext {InSelectStmt : true }, 32 },
67+ {& stmtctx.StatementContext {IgnoreTruncate : true }, 1 },
68+ {& stmtctx.StatementContext {TruncateAsWarning : true }, 2 },
69+ {& stmtctx.StatementContext {OverflowAsWarning : true }, 64 },
70+ {& stmtctx.StatementContext {IgnoreZeroInDate : true }, 128 },
71+ {& stmtctx.StatementContext {DividedByZeroAsWarning : true }, 256 },
72+ {& stmtctx.StatementContext {PadCharToFullLength : true }, 4 },
73+ {& stmtctx.StatementContext {InLoadDataStmt : true }, 1024 },
74+ {& stmtctx.StatementContext {InSelectStmt : true , TruncateAsWarning : true }, 34 },
75+ {& stmtctx.StatementContext {DividedByZeroAsWarning : true , IgnoreTruncate : true }, 257 },
76+ {& stmtctx.StatementContext {InUpdateStmt : true , IgnoreZeroInDate : true , InLoadDataStmt : true }, 1168 },
4577 }
46- fields := c . ToZapFields ()
47- if len ( fields ) != 9 {
48- t . Fatal ( c )
78+ for _ , tt := range testCases {
79+ got := tt . in . PushDownFlags ()
80+ c . Assert ( got , Equals , tt . out , Commentf ( "get %v, want %v" , got , tt . out ) )
4981 }
5082}
0 commit comments