Skip to content

Commit

Permalink
hide xorg command output by default, keep track of our temp files and…
Browse files Browse the repository at this point in the history
… make sure we delete them

git-svn-id: https://xpra.org/svn/Xpra/trunk@19395 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed May 24, 2018
1 parent 3655f7d commit cdb2e1d
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/unittests/unit/server_test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
SERVER_TIMEOUT = envint("XPRA_TEST_SERVER_TIMEOUT", 8)
XVFB_TIMEOUT = envint("XPRA_TEST_XVFB_TIMEOUT", 8)
DELETE_TEMP_FILES = envbool("XPRA_DELETE_TEMP_FILES", True)
SHOW_XORG_OUTPUT = envbool("XPRA_SHOW_XORG_OUTPUT", False)


class ServerTestUtil(unittest.TestCase):
Expand All @@ -35,6 +36,7 @@ def displays(cls):

@classmethod
def setUpClass(cls):
cls.temp_files = []
from xpra.server.server_util import find_log_dir
os.environ["XPRA_LOG_DIR"] = find_log_dir()
cls.default_config = get_defaults()
Expand All @@ -61,6 +63,12 @@ def tearDownClass(cls):
log("stopping display %s" % x)
proc = cls.run_xpra(["stop", x])
proc.communicate(None)
if DELETE_TEMP_FILES:
for x in cls.temp_files:
try:
os.unlink(x)
except:
pass


@classmethod
Expand Down Expand Up @@ -98,11 +106,11 @@ def run_command(cls, command, env=None, **kwargs):
log("run_command(%s, %s)", command, repr_ellipsized(str(env), 40))
else:
if "stdout" not in kwargs:
stdout_file = cls._temp_file()
stdout_file = cls._temp_file(prefix="xpra-stdout-")
kwargs["stdout"] = stdout_file
log("stdout=%s for %s", stdout_file.name, strcommand)
if "stderr" not in kwargs:
stderr_file = cls._temp_file()
stderr_file = cls._temp_file(prefix="xpra-stderr-")
kwargs["stderr"] = stderr_file
log("stderr=%s for %s", stderr_file.name, strcommand)
try:
Expand All @@ -124,11 +132,12 @@ def get_command_output(cls, command, env=None, **kwargs):


@classmethod
def _temp_file(self, data=None):
f = tempfile.NamedTemporaryFile(prefix='xpra-', delete=DELETE_TEMP_FILES)
def _temp_file(self, data=None, prefix="xpra-"):
f = tempfile.NamedTemporaryFile(prefix=prefix, delete=DELETE_TEMP_FILES)
if data:
f.file.write(data)
f.file.flush()
self.temp_files.append(f.name)
return f


Expand Down Expand Up @@ -207,7 +216,15 @@ def start_Xvfb(cls, display=None, screens=[(1024,768)]):
os.environ["XPRA_LOG_DIR"] = "/tmp"
cmd_expanded = [osexpand(v) for v in cmd]
cmdstr = " ".join("'%s'" % x for x in cmd_expanded)
xvfb = cls.run_command(cmd_expanded, stdout=sys.stdout, stderr=sys.stderr)
if SHOW_XORG_OUTPUT:
stdout = sys.stdout
stderr = sys.stderr
else:
stdout = cls._temp_file(prefix="Xorg-stdout-")
log("stdout=%s for %s", stdout.name, cmd)
stderr = cls._temp_file(prefix="Xorg-stderr-")
log("stderr=%s for %s", stderr.name, cmd)
xvfb = cls.run_command(cmd_expanded, stdout=stdout, stderr=stderr)
time.sleep(1)
print("xvfb(%s)=%s" % (cmdstr, xvfb))
assert pollwait(xvfb, XVFB_TIMEOUT) is None, "xvfb command \"%s\" failed and returned %s" % (cmdstr, xvfb.poll())
Expand All @@ -234,13 +251,15 @@ def check_server(cls, subcommand, display, *args):
assert display in live, "server display '%s' not found in live displays %s" % (display, live)
#query it:
info = cls.run_xpra(["version", display])
for _ in range(5):
for _ in range(20):
r = pollwait(info)
log("version for %s returned %s", display, r)
if r is not None:
assert r==0, "version failed for %s, returned %s" % (display, info.poll())
if r==1:
continue
break
time.sleep(1)
assert r==0, "version failed for %s, returned %s" % (display, info.poll())
return server_proc

@classmethod
Expand Down

0 comments on commit cdb2e1d

Please sign in to comment.