Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
blechschmidt committed Jun 23, 2024
1 parent c60a1d5 commit 543ba3e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import fcntl
import json
import os
import select
import socket
import subprocess
import tempfile
Expand Down Expand Up @@ -58,7 +60,7 @@ def start(self):
self.read_fd, write_fd = os.pipe()
self.process = subprocess.Popen(
['pallium', 'run', '--pid-file', '/proc/self/fd/%d' % write_fd, '--quiet', self.profile_path],
pass_fds=[write_fd])
pass_fds=[write_fd], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
self.wait_for_startup()

def close(self):
Expand All @@ -71,7 +73,17 @@ def close(self):
self.tempfile = None

def wait_for_startup(self):
os.read(self.read_fd, 1)
flag = fcntl.fcntl(self.read_fd, fcntl.F_GETFL)
fcntl.fcntl(self.read_fd, fcntl.F_SETFL, flag | os.O_NONBLOCK)
while True:
rlist, _, _ = select.select([self.read_fd], [], [], 0.3)
if len(rlist) > 0:
os.read(self.read_fd, 1)
break
exit_code = self.process.poll()
if exit_code is not None and exit_code != 0:
raise subprocess.CalledProcessError(exit_code, 'Pallium terminated with a non-zero exit code '
'and did not write to the PID file.')

def exec(self, command, stripped=True):
return pallium_exec_profile_path(self.profile_path, command, stripped).decode()
Expand Down

0 comments on commit 543ba3e

Please sign in to comment.