mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Stopped long queries, Read is_open() through TLS, Simplified answers and paging
- [server] query_time_limit (20 s by default) stops a client's query through SQLite's progress handler: refused with QueryTimedOut (11). A client closing while its query runs stops it too. - The answer timeout in the DLL (BakaShrot_SetAnswerTimeout / GetAnswerTimeout, kept across connections), Python (answer_timeout) and C# (AnswerTimeoutMs); QueryTimedOut in every binding. - is_open() reads what's waiting through TLS: a close_notify says closed, TLS's own records keep it open, unasked data or a broken stream close it. - The Rust client checks an answer's type in one place (TryFrom per packet); Client::wait() pings while waiting (the tool's --follow). - Pair::from(&Head), heads_after taking a Pair; simpler SyncState paging on both ends; the writer's redundant rollback check dropped. - codes.rs: the bindings' error codes and copied values match Rust's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ import threading
|
||||
import time
|
||||
|
||||
import bakashrot
|
||||
from bakashrot import AuthError, BakaShrotError, Client, ConnectionLostError, ErrorCode, RefusedError
|
||||
from bakashrot import ANSWER_TIMEOUT_SECONDS, AuthError, BakaShrotError, Client, ConnectionLostError, ErrorCode, RefusedError
|
||||
|
||||
dll_path, folder = sys.argv[1:3]
|
||||
fails = 0
|
||||
@@ -226,6 +226,26 @@ with kitchen:
|
||||
kitchen.ping()
|
||||
check("ping(): answered, still connected", kitchen.connected)
|
||||
|
||||
# --- The answer timeout ----------------------------------------------------
|
||||
check("answer_timeout: 30 s until changed", kitchen.answer_timeout == ANSWER_TIMEOUT_SECONDS, kitchen.answer_timeout)
|
||||
ok, detail = raises(lambda: setattr(kitchen, "answer_timeout", 0), BakaShrotError, "1 ms or more", ErrorCode.INVALID_ARGUMENT)
|
||||
check("answer_timeout = 0: refused", ok and kitchen.answer_timeout == ANSWER_TIMEOUT_SECONDS, detail)
|
||||
slow = Client.from_file(os.path.join(folder, "kitchen.toml"), dll_path)
|
||||
slow.answer_timeout = 0.3
|
||||
slow.connect()
|
||||
forever = "WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n) SELECT count(*) FROM n"
|
||||
started = time.perf_counter()
|
||||
ok, detail = raises(lambda: slow.query(forever), ConnectionLostError, code=ErrorCode.CONNECTION_LOST)
|
||||
elapsed = time.perf_counter() - started
|
||||
check("A query past answer_timeout (0.3 s, set before connecting): ConnectionLostError, disconnected",
|
||||
ok and elapsed < 5 and not slow.connected, f"{detail}, {elapsed * 1000:.0f} ms")
|
||||
slow.connect()
|
||||
slow.answer_timeout = 0.2
|
||||
check("answer_timeout set while connected: kept, the connection too", slow.answer_timeout == 0.2 and slow.connected)
|
||||
ok, detail = raises(lambda: slow.query(forever), ConnectionLostError, code=ErrorCode.CONNECTION_LOST)
|
||||
check("A query past it again: ConnectionLostError", ok, detail)
|
||||
slow.close()
|
||||
|
||||
# --- Two Clients, two threads, at the same time --------------------------
|
||||
other = Client.from_file(os.path.join(folder, "kitchen.toml"), dll_path).connect()
|
||||
pushed = {}
|
||||
|
||||
Reference in New Issue
Block a user