Skip to content
12 changes: 6 additions & 6 deletions boltstub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,16 @@ def play(self):
# `try_skip_to_end` being called from the interrupt handler
# in `__main__.py` which spawns a new thread. Without this
# `sleep`, the main thread that keeps calling
# `script.consume` only releases Script's internal lock so
# briefly that `try_skip_to_end` hangs unnecessarily long
# `script.consume` only releases Script's internal lock so
# briefly that `try_skip_to_end` can't reliably acquire it
# thus hanging unnecessarily long.
time.sleep(0.000001)
continue
except OSError as e:
# It's likely the client has gone away, so we can
# safely drop out and silence the error. There's no
# point in flagging a broken client from a test helper.
self.log("S: <BROKEN> %r", e)
return
self.script.try_skip_to_end(self.channel)
if not self.script.done(self.channel):
raise
self.log("Script finished")

def try_skip_to_end(self):
Expand Down
8 changes: 2 additions & 6 deletions boltstub/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,14 +1213,10 @@ def has_deterministic_end(self) -> bool:
return self.blocks[-1].has_deterministic_end()

def init(self, channel):
while True:
while self.index < len(self.blocks):
block = self.blocks[self.index]
block.init(channel)
if (
not block.has_deterministic_end()
or not block.done(channel)
or self.index + 1 >= len(self.blocks)
):
if not block.has_deterministic_end() or not block.done(channel):
break
self.index += 1

Expand Down
11 changes: 9 additions & 2 deletions boltstub/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,17 @@ def test_restarting(server_factory, restarting, concurrent,
"!: ALLOW CONCURRENT\n" if concurrent else "",
)

server = server_factory(parse(script))
if restarting and concurrent:
with pytest.warns(
Warning, match="concurrent scripts are implicitly restarting"
):
server = server_factory(parse(script))
else:
server = server_factory(parse(script))

for i in range(3):
if i > 0 and not (restarting or concurrent):
with pytest.raises((ConnectionError, OSError, BrokenSocket)):
with pytest.raises((OSError, BrokenSocket)):
con = connection_factory("localhost", 7687)
con.write(b"\x60\x60\xb0\x17")
con.write(server_version_to_version_request((4, 3)))
Expand Down