Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: randomly allocate a isolation level for txn when create test case #58

Open
wants to merge 2 commits into
base: coo-consistency-check
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion src/dbtest/src/mda_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

from operator import truediv
import os
import random
import sys


class OptionException(Exception):
pass

Expand All @@ -36,6 +36,26 @@ def __init__(self, op_type, txn_num, op_num):
self.txn_num = txn_num
self.op_num = op_num

"""
Initialize supported isolation levels for different databases

Args:
- db_type (str): The type of database being used.

Returns:
set: the supported isolation levels.

"""
def init_isolation_levels(db_type):
isolation_levels = list()
if 'mysql' in db_type.lower():
isolation_levels = [
"READ UNCOMMITTED",
"READ COMMITTED",
"REPEATABLE READ",
"SERIALIZABLE"
]
return isolation_levels

"""
Initialize tables for database testing.
Expand Down Expand Up @@ -804,6 +824,37 @@ def write_description(file_name, txn_num, op_num, data_num):
description += "#\n"
file_test.write(description)


"""
Write random transaction isolation levels to the specified file.

Args:
- file_name (str): The name of the file where the description will be written.
- txn_num (int): The number of transactions.
- isolation_levels (string {}): The isolation levels set supported by database

This function writes transaction isolation level for the test case to the specified file. the transaction isolation level
is randomly choiced from the supported isolation level of database.

"""

def write_isolation_level(file_name, txn_num, isolation_levels):
if len(isolation_levels) == 0:
return

isolation_level_descprtion = ""
description = ""
for i in range(txn_num):
isolation_level = random.choice(isolation_levels)
if isolation_level_descprtion:
isolation_level_descprtion += ","
isolation_level_descprtion += "T" + str(i + 1) +":" + isolation_level
description += "Txn Isolation: " + isolation_level_descprtion + "\n"

with open(file_name, "a+") as file_test:
file_test.write(description)


# target folder
case_folder = "t/test_case_v2"
# pattern files
Expand Down Expand Up @@ -846,9 +897,12 @@ def write_description(file_name, txn_num, op_num, data_num):
table_num = 1
sql_count, txn_count = 0, 1

isolation_levels = init_isolation_levels(db_type)
# description
write_description(file_name, num, num, num)

write_isolation_level(file_name, num, isolation_levels)

# preparation
data_num = init_table(file_name, sql_count, txn_count, table_num, db_type, test_type)

Expand Down