Skip to content

Commit

Permalink
Wait for pid death
Browse files Browse the repository at this point in the history
  • Loading branch information
bojanserafimov committed Aug 12, 2022
1 parent bd33ea9 commit 21089d5
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions test_runner/fixtures/neon_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1488,17 +1488,25 @@ def start(self, overrides=()) -> 'NeonPageserver':
self.running = True
return self

def _wait_for_death(self):
"""Wait for pageserver to die. Assumes kill signal is sent."""
pid_path = pathlib.Path(self.env.repo_dir) / "pageserver.pid"
pid = read_pid(pid_path)
retries_left = 20
while check_pid(pid):
time.sleep(0.1)
retries_left -= 1
if retries_left == 0:
raise AssertionError("Pageserver failed to die")

def stop(self, immediate=False) -> 'NeonPageserver':
"""
Stop the page server.
Returns self.
"""
if self.running:
self.env.neon_cli.pageserver_stop(immediate)
# HACK This fixes https://github.com/neondatabase/neon/issues/2247
# in most cases, but we should probably wait on some event rather
# than wait 0.1 seconds.
time.sleep(0.1)
self._wait_for_death()
self.running = False
return self

Expand Down Expand Up @@ -2008,6 +2016,17 @@ def read_pid(path: Path) -> int:
return int(path.read_text())


def check_pid(pid):
"""Check whether pid is running."""
try:
# If sig is 0, then no signal is sent, but error checking is still performed.
os.kill(pid, 0)
except OSError:
return False
else:
return True


@dataclass
class SafekeeperPort:
pg: int
Expand Down

0 comments on commit 21089d5

Please sign in to comment.