@@ -23,17 +23,13 @@ import (
23
23
"github.com/pingcap/errors"
24
24
"github.com/pingcap/tidb/pkg/errctx"
25
25
"github.com/pingcap/tidb/pkg/expression/exprctx"
26
- "github.com/pingcap/tidb/pkg/expression/exprstatic"
27
- "github.com/pingcap/tidb/pkg/lightning/backend/encode"
28
- "github.com/pingcap/tidb/pkg/lightning/log"
29
26
"github.com/pingcap/tidb/pkg/meta/model"
30
27
"github.com/pingcap/tidb/pkg/parser/mysql"
31
28
"github.com/pingcap/tidb/pkg/sessionctx/stmtctx"
32
29
"github.com/pingcap/tidb/pkg/sessionctx/variable"
33
30
"github.com/pingcap/tidb/pkg/table/tblctx"
34
31
"github.com/pingcap/tidb/pkg/types"
35
32
contextutil "github.com/pingcap/tidb/pkg/util/context"
36
- "github.com/pingcap/tidb/pkg/util/deeptest"
37
33
"github.com/pingcap/tidb/pkg/util/rowcodec"
38
34
"github.com/pingcap/tidb/pkg/util/timeutil"
39
35
"github.com/stretchr/testify/require"
@@ -126,63 +122,10 @@ func TestLitExprContext(t *testing.T) {
126
122
},
127
123
}
128
124
129
- // We need to compare the new introduced `*litExprContext` the same behavior with the old `session`.
130
- // After refactoring finished, we can remove the old session and this test.
131
- compareWithLegacySession := func (t * testing.T , ctx * litExprContext , opts * encode.SessionOptions ) {
132
- if opts .SysVars == nil {
133
- opts .SysVars = make (map [string ]string )
134
- }
135
- if _ , ok := opts .SysVars ["div_precision_increment" ]; ! ok {
136
- // It seems that `DefDivPrecisionIncrement` is not set as a default value in `newSession` and its
137
- // default value is 0.
138
- // We should set it manually to make test pass.
139
- // The legacy code has no bug for this default value because the `DefaultImportantVariables`
140
- // will be loaded every time to override this variable:
141
- // https://github.com/pingcap/tidb/blob/2e457b394f09165e23fa5121fcfd89c6e8a6e835/pkg/lightning/common/common.go#L33-L42
142
- opts .SysVars ["div_precision_increment" ] = strconv .Itoa (variable .DefDivPrecisionIncrement )
143
- }
144
- if _ , ok := opts .SysVars ["block_encryption_mode" ]; ! ok {
145
- // same reason with `DivPrecisionIncrement`, we need to set `block_encryption_mode` manually to pass test.
146
- opts .SysVars ["block_encryption_mode" ] = variable .DefBlockEncryptionMode
147
- }
148
- se := newSession (opts , log .L ())
149
- seCtx := exprstatic .MakeExprContextStatic (se .exprCtx .ExprContext )
150
- deeptest .AssertDeepClonedEqual (t , seCtx , ctx .ExprContext , deeptest .WithIgnorePath ([]string {
151
- "$.exprCtxState.evalCtx.id" ,
152
- "$.exprCtxState.evalCtx.evalCtxState.typeCtx.loc" ,
153
- "$.exprCtxState.evalCtx.evalCtxState.warnHandler" ,
154
- "$.exprCtxState.evalCtx.evalCtxState.typeCtx.warnHandler" ,
155
- "$.exprCtxState.evalCtx.evalCtxState.errCtx.warnHandler" ,
156
- "$.exprCtxState.evalCtx.evalCtxState.currentTime" ,
157
- "$.exprCtxState.evalCtx.evalCtxState.requestVerificationFn" ,
158
- "$.exprCtxState.evalCtx.evalCtxState.requestDynamicVerificationFn" ,
159
- "$.exprCtxState.rng" ,
160
- "$.exprCtxState.planCacheTracker" ,
161
- }))
162
- currentTime , err := seCtx .GetEvalCtx ().CurrentTime ()
163
- require .NoError (t , err )
164
- seTime , err := seCtx .GetEvalCtx ().CurrentTime ()
165
- require .NoError (t , err )
166
- if opts .Timestamp == 0 {
167
- require .InDelta (t , seTime .Unix (), currentTime .Unix (), 2 )
168
- } else {
169
- require .Equal (t , opts .Timestamp * 1000000000 , currentTime .UnixNano ())
170
- require .Equal (t , seTime .UnixNano (), currentTime .UnixNano ())
171
- }
172
- require .Equal (t , seCtx .GetEvalCtx ().Location ().String (), ctx .GetEvalCtx ().Location ().String ())
173
- }
174
-
175
125
for i , c := range cases {
176
126
t .Run ("case-" + strconv .Itoa (i ), func (t * testing.T ) {
177
127
ctx , err := newLitExprContext (c .sqlMode , c .sysVars , c .timestamp )
178
128
require .NoError (t , err )
179
-
180
- compareWithLegacySession (t , ctx , & encode.SessionOptions {
181
- SQLMode : c .sqlMode ,
182
- SysVars : c .sysVars ,
183
- Timestamp : c .timestamp ,
184
- })
185
-
186
129
evalCtx := ctx .GetEvalCtx ()
187
130
require .Equal (t , c .sqlMode , evalCtx .SQLMode ())
188
131
tc , ec := evalCtx .TypeCtx (), evalCtx .ErrCtx ()
@@ -314,31 +257,6 @@ func TestLitTableMutateContext(t *testing.T) {
314
257
require .Empty (t , tblCtx .GetColumnSize (456 ))
315
258
}
316
259
317
- // We need to compare the new introduced `*litTableMutateContext` the same behavior with the old `session`.
318
- // After refactoring finished, we can remove the old session and this test.
319
- compareWithLegacySession := func (ctx * litTableMutateContext , vars map [string ]string ) {
320
- se := newSession (& encode.SessionOptions {
321
- SQLMode : mysql .ModeNone ,
322
- SysVars : vars ,
323
- }, log .L ())
324
- // make sure GetRowIDShardGenerator() internal assertion pass
325
- se .GetSessionVars ().TxnCtx = & variable.TransactionContext {}
326
- se .GetSessionVars ().TxnCtx .StartTS = 123
327
- seCtx := se .GetTableCtx ()
328
- require .Equal (t , seCtx .ConnectionID (), ctx .ConnectionID ())
329
- require .Equal (t , seCtx .InRestrictedSQL (), ctx .InRestrictedSQL ())
330
- require .Equal (t , seCtx .TxnAssertionLevel (), ctx .TxnAssertionLevel ())
331
- require .Equal (t , seCtx .GetMutateBuffers (), ctx .GetMutateBuffers ())
332
- require .Equal (t , seCtx .EnableMutationChecker (), ctx .EnableMutationChecker ())
333
- require .Equal (t , seCtx .GetRowEncodingConfig (), ctx .GetRowEncodingConfig ())
334
- require .Equal (t , seCtx .GetRowIDShardGenerator ().GetShardStep (), ctx .GetRowIDShardGenerator ().GetShardStep ())
335
- seAlloc , ok := seCtx .GetReservedRowIDAlloc ()
336
- require .True (t , ok )
337
- alloc , ok := ctx .GetReservedRowIDAlloc ()
338
- require .True (t , ok )
339
- require .Equal (t , seAlloc , alloc )
340
- }
341
-
342
260
// test for default
343
261
tblCtx , err := newLitTableMutateContext (exprCtx , nil )
344
262
require .NoError (t , err )
@@ -353,7 +271,6 @@ func TestLitTableMutateContext(t *testing.T) {
353
271
g := tblCtx .GetRowIDShardGenerator ()
354
272
require .NotNil (t , g )
355
273
require .Equal (t , variable .DefTiDBShardAllocateStep , g .GetShardStep ())
356
- compareWithLegacySession (tblCtx , nil )
357
274
358
275
// test for load vars
359
276
sysVars := map [string ]string {
@@ -375,7 +292,6 @@ func TestLitTableMutateContext(t *testing.T) {
375
292
require .NotNil (t , g )
376
293
require .NotEqual (t , variable .DefTiDBShardAllocateStep , g .GetShardStep ())
377
294
require .Equal (t , 1234567 , g .GetShardStep ())
378
- compareWithLegacySession (tblCtx , sysVars )
379
295
380
296
// test for `RowEncodingConfig.IsRowLevelChecksumEnabled` which should be loaded from global variable.
381
297
require .False (t , variable .EnableRowLevelChecksum .Load ())
@@ -390,5 +306,4 @@ func TestLitTableMutateContext(t *testing.T) {
390
306
IsRowLevelChecksumEnabled : true ,
391
307
RowEncoder : & rowcodec.Encoder {Enable : true },
392
308
}, tblCtx .GetRowEncodingConfig ())
393
- compareWithLegacySession (tblCtx , sysVars )
394
309
}
0 commit comments