mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-19 09:34:18 +01:00
add more logging to antithesis tests
format python tests
This commit is contained in:
@@ -4,6 +4,7 @@ import logging
|
|||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
|
|
||||||
import turso
|
import turso
|
||||||
|
from antithesis.assertions import reachable
|
||||||
from antithesis.random import get_random
|
from antithesis.random import get_random
|
||||||
|
|
||||||
handler = RotatingFileHandler(
|
handler = RotatingFileHandler(
|
||||||
@@ -37,8 +38,10 @@ def transaction():
|
|||||||
|
|
||||||
logger.info(f"Sender ID: {sender} | Recipient ID: {recipient} | Txn Val: {value}")
|
logger.info(f"Sender ID: {sender} | Recipient ID: {recipient} | Txn Val: {value}")
|
||||||
|
|
||||||
|
reachable("[GENERATE TRANSACTION] BEGIN TRANSACTION")
|
||||||
cur.execute("BEGIN TRANSACTION;")
|
cur.execute("BEGIN TRANSACTION;")
|
||||||
|
|
||||||
|
reachable("[GENERATE TRANSACTION] UPDATE ACCOUNTS - subtract value from balance of the sender account")
|
||||||
# subtract value from balance of the sender account
|
# subtract value from balance of the sender account
|
||||||
cur.execute(f"""
|
cur.execute(f"""
|
||||||
UPDATE accounts
|
UPDATE accounts
|
||||||
@@ -46,6 +49,7 @@ def transaction():
|
|||||||
WHERE account_id = {sender};
|
WHERE account_id = {sender};
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
reachable("[GENERATE TRANSACTION] UPDATE ACCOUNTS - add value to balance of the recipient account")
|
||||||
# add value to balance of the recipient account
|
# add value to balance of the recipient account
|
||||||
cur.execute(f"""
|
cur.execute(f"""
|
||||||
UPDATE accounts
|
UPDATE accounts
|
||||||
@@ -53,6 +57,7 @@ def transaction():
|
|||||||
WHERE account_id = {recipient};
|
WHERE account_id = {recipient};
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
reachable("[GENERATE TRANSACTION] COMMIT TRANSACTION")
|
||||||
cur.execute("COMMIT;")
|
cur.execute("COMMIT;")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ cur_init = con_init.cursor()
|
|||||||
|
|
||||||
tbl_len = cur_init.execute("SELECT count FROM tables").fetchone()[0]
|
tbl_len = cur_init.execute("SELECT count FROM tables").fetchone()[0]
|
||||||
selected_tbl = get_random() % tbl_len
|
selected_tbl = get_random() % tbl_len
|
||||||
tbl_schema = json.loads(cur_init.execute(
|
tbl_schema = json.loads(cur_init.execute(f"SELECT schema FROM schemas WHERE tbl = {selected_tbl}").fetchone()[0])
|
||||||
f"SELECT schema FROM schemas WHERE tbl = {selected_tbl}").fetchone()[0])
|
|
||||||
|
|
||||||
tbl_name = f"tbl_{selected_tbl}"
|
tbl_name = f"tbl_{selected_tbl}"
|
||||||
|
|
||||||
@@ -29,8 +28,7 @@ except Exception as e:
|
|||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
cur.execute(
|
cur.execute("SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = '" + tbl_name + "'")
|
||||||
"SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = '" + tbl_name + "'")
|
|
||||||
|
|
||||||
result = cur.fetchone()
|
result = cur.fetchone()
|
||||||
|
|
||||||
@@ -47,10 +45,8 @@ cur.execute("ALTER TABLE " + tbl_name + " RENAME TO " + tbl_name + "_old")
|
|||||||
con.rollback()
|
con.rollback()
|
||||||
|
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
cur.execute(
|
cur.execute("SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = '" + tbl_name + "'")
|
||||||
"SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = '" + tbl_name + "'")
|
|
||||||
|
|
||||||
schema_after = cur.fetchone()[0]
|
schema_after = cur.fetchone()[0]
|
||||||
|
|
||||||
always(schema_before == schema_after,
|
always(schema_before == schema_after, "schema should be the same after rollback", {})
|
||||||
"schema should be the same after rollback", {})
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ dev = [
|
|||||||
"mypy==1.11.0",
|
"mypy==1.11.0",
|
||||||
"pytest==8.3.1",
|
"pytest==8.3.1",
|
||||||
"pytest-cov==5.0.0",
|
"pytest-cov==5.0.0",
|
||||||
"ruff==0.5.4",
|
"ruff>=0.12.2",
|
||||||
"coverage==7.6.1",
|
"coverage==7.6.1",
|
||||||
"maturin==1.7.8",
|
"maturin==1.7.8",
|
||||||
]
|
]
|
||||||
@@ -80,6 +80,6 @@ dev = [
|
|||||||
"pluggy>=1.6.0",
|
"pluggy>=1.6.0",
|
||||||
"pytest>=8.3.1",
|
"pytest>=8.3.1",
|
||||||
"pytest-cov>=5.0.0",
|
"pytest-cov>=5.0.0",
|
||||||
"ruff>=0.5.4",
|
"ruff>=0.12.2",
|
||||||
"typing-extensions>=4.13.0",
|
"typing-extensions>=4.13.0",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -45,4 +45,3 @@ def main() -> None:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|||||||
@@ -52,4 +52,3 @@ def main() -> None:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|||||||
@@ -135,9 +135,9 @@ INSERT INTO t VALUES (zeroblob(1024 - 1), zeroblob(1024 - 2), zeroblob(1024 - 3)
|
|||||||
def run_test(self, name: str, sql: str, expected: str) -> None:
|
def run_test(self, name: str, sql: str, expected: str) -> None:
|
||||||
console.test(f"Running test: {name}", _stack_offset=2)
|
console.test(f"Running test: {name}", _stack_offset=2)
|
||||||
actual = self.shell.execute(sql)
|
actual = self.shell.execute(sql)
|
||||||
assert actual == expected, (
|
assert (
|
||||||
f"Test failed: {name}\nSQL: {sql}\nExpected:\n{repr(expected)}\nActual:\n{repr(actual)}"
|
actual == expected
|
||||||
)
|
), f"Test failed: {name}\nSQL: {sql}\nExpected:\n{repr(expected)}\nActual:\n{repr(actual)}"
|
||||||
|
|
||||||
def run_debug(self, sql: str):
|
def run_debug(self, sql: str):
|
||||||
console.debug(f"debugging: {sql}", _stack_offset=2)
|
console.debug(f"debugging: {sql}", _stack_offset=2)
|
||||||
|
|||||||
Reference in New Issue
Block a user