mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-19 09:34:18 +01:00
Merge 'Improve extension compatibility testing' from Piotr Rżysko
Extracted from https://github.com/tursodatabase/limbo/pull/1727. Reviewed-by: Preston Thorpe (@PThorpe92) Closes #1741
This commit is contained in:
@@ -54,8 +54,7 @@ class LimboShell:
|
||||
return ""
|
||||
self._write_to_pipe(f"SELECT '{end_marker}';")
|
||||
output = ""
|
||||
done = False
|
||||
while not done:
|
||||
while True:
|
||||
ready, _, errors = select.select(
|
||||
[self.pipe.stdout, self.pipe.stderr],
|
||||
[],
|
||||
@@ -63,12 +62,17 @@ class LimboShell:
|
||||
)
|
||||
ready_or_errors = set(ready + errors)
|
||||
if self.pipe.stderr in ready_or_errors:
|
||||
done = self._handle_error()
|
||||
fragment = self.pipe.stderr.read(PIPE_BUF).decode()
|
||||
if not fragment:
|
||||
console.error(output, end="", _stack_offset=2)
|
||||
raise RuntimeError("Error encountered in Limbo shell.")
|
||||
output += fragment
|
||||
if self.pipe.stdout in ready_or_errors:
|
||||
fragment = self.pipe.stdout.read(PIPE_BUF).decode()
|
||||
output += fragment
|
||||
if output.rstrip().endswith(end_marker):
|
||||
return self._clean_output(output, end_marker)
|
||||
break
|
||||
return self._clean_output(output, end_marker)
|
||||
|
||||
def _write_to_pipe(self, command: str) -> None:
|
||||
if not self.pipe.stdin:
|
||||
@@ -76,14 +80,6 @@ class LimboShell:
|
||||
self.pipe.stdin.write((command + "\n").encode())
|
||||
self.pipe.stdin.flush()
|
||||
|
||||
def _handle_error(self) -> None:
|
||||
while True:
|
||||
chunk = self.pipe.stderr.read(PIPE_BUF).decode()
|
||||
if not chunk:
|
||||
break # EOF
|
||||
console.error(chunk, end="", _stack_offset=2)
|
||||
raise RuntimeError("Error encountered in Limbo shell.")
|
||||
|
||||
@staticmethod
|
||||
def _clean_output(output: str, marker: str) -> str:
|
||||
output = output.rstrip().removesuffix(marker)
|
||||
|
||||
Reference in New Issue
Block a user