Skip to content

Commit

Permalink
sessionctx/variable: add tests to ensure skipInit can be removed (#35703
Browse files Browse the repository at this point in the history
)

ref #35051
  • Loading branch information
morgo authored Jun 28, 2022
1 parent 8097685 commit 27e7bbd
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,92 @@ func TestSettersandGetters(t *testing.T) {
}
}

// TestSkipInitIsUsed ensures that no new variables are added with skipInit: true.
// This feature is deprecated, and if you need to run code to differentiate between init and "SET" (rare),
// you can instead check if s.StmtCtx.StmtType == "Set".
// The reason it is deprecated is that the behavior is typically wrong:
// it means session settings won't inherit from global and don't apply until you first set
// them in each session. This is a very weird behavior.
// See: https://github.com/pingcap/tidb/issues/35051
func TestSkipInitIsUsed(t *testing.T) {
for _, sv := range GetSysVars() {
if sv.skipInit {
// Many of these variables might allow skipInit to be removed,
// they need to be checked first. The purpose of this test is to make
// sure we don't introduce any new variables with skipInit, which seems
// to be a problem.
switch sv.Name {
case Timestamp,
WarningCount,
ErrorCount,
LastInsertID,
Identity,
TiDBTxnScope,
TiDBSnapshot,
TiDBOptDistinctAggPushDown,
TiDBOptWriteRowID,
TiDBChecksumTableConcurrency,
TiDBBatchInsert,
TiDBBatchDelete,
TiDBBatchCommit,
TiDBCurrentTS,
TiDBLastTxnInfo,
TiDBLastQueryInfo,
TiDBEnableChunkRPC,
TxnIsolationOneShot,
TiDBOptimizerSelectivityLevel,
TiDBOptimizerEnableOuterJoinReorder,
TiDBLogFileMaxDays,
TiDBConfig,
TiDBDDLReorgPriority,
TiDBSlowQueryFile,
TiDBWaitSplitRegionFinish,
TiDBWaitSplitRegionTimeout,
TiDBLowResolutionTSO,
TiDBAllowRemoveAutoInc,
TiDBMetricSchemaStep,
TiDBMetricSchemaRangeDuration,
TiDBFoundInPlanCache,
TiDBFoundInBinding,
RandSeed1,
RandSeed2,
TiDBLastDDLInfo,
TiDBGeneralLog,
TiDBSlowLogThreshold,
TiDBRecordPlanInSlowLog,
TiDBEnableSlowLog,
TiDBCheckMb4ValueInUTF8,
TiDBPProfSQLCPU,
TiDBDDLSlowOprThreshold,
TiDBForcePriority,
TiDBMemoryUsageAlarmRatio,
TiDBEnableCollectExecutionInfo,
TiDBPersistAnalyzeOptions,
TiDBEnableColumnTracking,
TiDBStatsLoadPseudoTimeout,
SQLLogBin,
ForeignKeyChecks,
CollationDatabase,
CharacterSetClient,
CharacterSetResults,
CollationConnection,
CharsetDatabase,
GroupConcatMaxLen,
CharacterSetConnection,
CharacterSetServer,
TiDBBuildStatsConcurrency,
TiDBOptTiFlashConcurrencyFactor,
TiDBOptSeekFactor,
TiDBOptJoinReorderThreshold,
TiDBStatsLoadSyncWait,
CharacterSetFilesystem:
continue
}
require.Equal(t, false, sv.skipInit, fmt.Sprintf("skipInit should not be set on new system variables. variable %s is in violation", sv.Name))
}
}
}

func TestSecureAuth(t *testing.T) {
sv := GetSysVar(SecureAuth)
vars := NewSessionVars()
Expand Down

0 comments on commit 27e7bbd

Please sign in to comment.