Skip to content

Commit f81183a

Browse files
trueeyumergify[bot]
authored andcommitted
[UT] No need to generate result in record mode for uncheck stmt (#72592)
Signed-off-by: trueeyu <lxhhust350@qq.com> (cherry picked from commit ae82a38) # Conflicts: # test/test_sql_cases.py
1 parent a12acd6 commit f81183a

2 files changed

Lines changed: 112 additions & 2 deletions

File tree

test/lib/sr_sql_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ def execute_thread(self, exec_id, cmd_list, res_list, ori_cmd_list, record_mode,
11531153

11541154
old_this_res_len = len(this_res)
11551155
actual_res, actual_res_log, var, order = self.execute_single_statement(
1156-
_each_cmd, _cmd_id_str, record_mode, this_res, var_key=exec_id, conn=conn
1156+
_each_cmd, _cmd_id_str, record_mode and not uncheck, this_res, var_key=exec_id, conn=conn
11571157
)
11581158

11591159
if record_mode:

test/test_sql_cases.py

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,9 @@ def test_sql_basic(self, case_info: choose_cases.ChooseCase.CaseTR):
439439
uncheck = True
440440
sql = sql[len(sr_sql_lib.UNCHECK_FLAG) :]
441441

442-
actual_res, actual_res_log, var, order = self.execute_single_statement(sql, sql_id, record_mode)
442+
actual_res, actual_res_log, var, order = self.execute_single_statement(
443+
sql, sql_id, record_mode and not uncheck
444+
)
443445

444446
if not record_mode and not uncheck:
445447
# check mode only work in validating mode
@@ -487,6 +489,114 @@ def test_sql_basic(self, case_info: choose_cases.ChooseCase.CaseTR):
487489
self.res_log.append("} END CLEANUP")
488490
# do nothing during execution here; cleanup executes in tearDown
489491
continue
492+
<<<<<<< HEAD
493+
=======
494+
elif isinstance(sql, dict) and sql.get("type", "") == SET_VAR_FLAG:
495+
# SET_VAR block: run SQL statements with each session variable combination
496+
combinations = sql["combinations"]
497+
set_var_stats = sql["stat"]
498+
set_var_results = sql.get("res", [])
499+
500+
self_print(
501+
f"\n[SET_VAR] Start: {len(combinations)} combination(s)...",
502+
color=ColorEnum.BLUE, logout=True, bold=True
503+
)
504+
505+
if record_mode:
506+
# Record mode: execute with first combination and record results,
507+
# then verify remaining combinations produce the same outcome.
508+
self.res_log.append(SET_VAR_FLAG + " {")
509+
self.res_log.append(" PROPERTY: %s" % json.dumps(combinations))
510+
511+
# --- first combination: execute & record ---
512+
first_combo = combinations[0]
513+
combo_desc = ", ".join(f"{k}={v}" for k, v in first_combo.items())
514+
self_print(
515+
f"[SET_VAR] Recording combination 1/{len(combinations)}: {combo_desc}",
516+
color=ColorEnum.BLUE, logout=True
517+
)
518+
for var_name, var_value in first_combo.items():
519+
self.execute_sql("SET %s = %s;" % (var_name, var_value))
520+
521+
ori_set_var = case_info.ori_sql[sql_id]
522+
for stmt_id, stmt in enumerate(set_var_stats):
523+
# append original statement text (with ${uuid} placeholders) to R file
524+
if isinstance(ori_set_var, dict):
525+
self.res_log.append(ori_set_var["stat"][stmt_id])
526+
else:
527+
self.res_log.append(stmt)
528+
529+
uncheck = False
530+
run_stmt = stmt
531+
if run_stmt.startswith(sr_sql_lib.UNCHECK_FLAG):
532+
uncheck = True
533+
run_stmt = run_stmt[len(sr_sql_lib.UNCHECK_FLAG):]
534+
535+
actual_res, actual_res_log, var, order = self.execute_single_statement(
536+
run_stmt, sql_id, not uncheck
537+
)
538+
539+
# --- remaining combinations: execute & verify against recorded results ---
540+
for combo_id, combo in enumerate(combinations[1:], 2):
541+
combo_desc = ", ".join(f"{k}={v}" for k, v in combo.items())
542+
self_print(
543+
f"[SET_VAR] Verifying combination {combo_id}/{len(combinations)}: {combo_desc}",
544+
color=ColorEnum.BLUE, logout=True
545+
)
546+
for var_name, var_value in combo.items():
547+
self.execute_sql("SET %s = %s;" % (var_name, var_value))
548+
549+
for stmt_id, stmt in enumerate(set_var_stats):
550+
run_stmt = stmt
551+
uncheck = False
552+
if run_stmt.startswith(sr_sql_lib.UNCHECK_FLAG):
553+
uncheck = True
554+
run_stmt = run_stmt[len(sr_sql_lib.UNCHECK_FLAG):]
555+
self.execute_single_statement(run_stmt, sql_id, False)
556+
557+
self.res_log.append("} " + END_SET_VAR_FLAG)
558+
559+
else:
560+
# Validation mode: run all combinations and check results
561+
for combo_id, combo in enumerate(combinations):
562+
combo_desc = ", ".join(f"{k}={v}" for k, v in combo.items())
563+
self_print(
564+
f"[SET_VAR] Combination {combo_id + 1}/{len(combinations)}: {combo_desc}",
565+
color=ColorEnum.BLUE, logout=True
566+
)
567+
568+
# set session variables for this combination
569+
for var_name, var_value in combo.items():
570+
self.execute_sql("SET %s = %s;" % (var_name, var_value))
571+
572+
# execute all statements and check results
573+
for stmt_id, stmt in enumerate(set_var_stats):
574+
uncheck = False
575+
ori_stmt = stmt
576+
577+
if stmt.startswith(sr_sql_lib.UNCHECK_FLAG):
578+
uncheck = True
579+
stmt = stmt[len(sr_sql_lib.UNCHECK_FLAG):]
580+
581+
actual_res, actual_res_log, var, order = self.execute_single_statement(
582+
stmt, sql_id, False
583+
)
584+
585+
if not uncheck and stmt_id < len(set_var_results):
586+
expect_res = set_var_results[stmt_id]
587+
expect_res_for_log = expect_res if len(expect_res) < 1000 else expect_res[:1000] + "..."
588+
589+
log.info(
590+
f"[SET_VAR {combo_id + 1}/{len(combinations)} - {stmt_id}.result]: "
591+
f"\n - [exp]: {expect_res_for_log}"
592+
f"\n - [act]: {actual_res}"
593+
)
594+
595+
self.check(sql_id, stmt, expect_res, actual_res, order, ori_stmt)
596+
597+
self_print(f"[SET_VAR] Finish!", color=ColorEnum.BLUE, logout=True, bold=True)
598+
599+
>>>>>>> ae82a38dba ([UT] No need to generate result in record mode for uncheck stmt (#72592))
490600
elif isinstance(sql, dict) and sql["type"] == sr_sql_lib.CONCURRENCY_FLAG:
491601
# concurrency statement
492602
self_print(f"[CONCURRENCY] Start...", color=ColorEnum.CYAN, logout=True)

0 commit comments

Comments
 (0)