Skip to content

Commit

Permalink
#1838: display is optional for unit tests (better not to use it on wi…
Browse files Browse the repository at this point in the history
…n32 and macos)

git-svn-id: https://xpra.org/svn/Xpra/trunk@19441 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed May 25, 2018
1 parent 904e2da commit ca73769
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
18 changes: 12 additions & 6 deletions src/unittests/unit/server/mixins/server_mixins_option_test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import os
import time
from collections import OrderedDict

Expand Down Expand Up @@ -72,12 +73,15 @@ def _test(self, subcommand="start", options={}):
args = ["--%s=%s" % (k,v) for k,v in options.items()]
xvfb = None
if WIN32 or OSX:
display = ":0"
display = ""
display_arg = []
elif self.display:
display = self.display
display_arg = [display]
args.append("--use-display")
else:
display = self.find_free_display()
display_arg = [display]
if subcommand=="shadow":
xvfb = self.start_Xvfb(display)
server = None
Expand All @@ -87,20 +91,22 @@ def _test(self, subcommand="start", options={}):
log("args=%s", " ".join("'%s'" % x for x in args))
server = self.check_server(subcommand, display, *args)
#we should always be able to get the version:
client = self.run_xpra(["version", display])
client = self.run_xpra(["version"]+display_arg)
assert pollwait(client, 5)==0, "version client failed to connect to server with args=%s" % args
#run info query:
cmd = ["info", display]
cmd = ["info"]+display_arg
client = self.run_xpra(cmd)
r = pollwait(client, 5)
assert r==0, "info client failed and returned %s for server with args=%s" % (r, args)
#connect a gui client:
if WIN32 or OSX or (self.client_display and self.client_xvfb):
xpra_args = ["attach", display]
env = {}
xpra_args = ["attach", "--clipboard=no"]+display_arg
kwargs = {}
if not (WIN32 or OSX):
env = os.environ.copy()
env["DISPLAY"] = self.client_display
gui_client = self.run_xpra(xpra_args, env)
kwargs = {"env" : env}
gui_client = self.run_xpra(xpra_args, **kwargs)
r = pollwait(gui_client, 5)
if r is not None:
log.warn("gui client stdout=%s", gui_client.stdout_file)
Expand Down
8 changes: 1 addition & 7 deletions src/unittests/unit/server/mixins/shadow_option_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ def test_start_all(self):


def main():
from xpra.os_util import WIN32
if not WIN32:
unittest.main()
#for running on win32:
#XPRA_WAIT_FOR_INPUT=0 XPRA_COMMAND=../scripts/xpra \
# PYTHONPATH=".;.." XPRA_TEST_DEBUG=1 XPRA_ALL_DEBUG=1 \
# ./unit/server/mixins/shadow_option_test.py
unittest.main()


if __name__ == '__main__':
Expand Down
35 changes: 24 additions & 11 deletions src/unittests/unit/server_test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,20 @@ def which(cls, cmd):
return cmd

@classmethod
def run_xpra(cls, xpra_args, env=None):
def run_xpra(cls, xpra_args, env=None, **kwargs):
xpra_cmd = get_xpra_command()
if xpra_cmd==["xpra"]:
xpra_cmd = [cls.which("xpra")]
cmd = ["python%i" % sys.version_info[0]] + xpra_cmd + cls.default_xpra_args + xpra_args
return cls.run_command(cmd, env)
return cls.run_command(cmd, env, **kwargs)

@classmethod
def run_command(cls, command, env=None, **kwargs):
if env is None:
env = cls.get_run_env()
env["XPRA_FLATTEN_INFO"] = "0"
if env is not None and not WIN32:
kwargs["env"] = env
stdout_file = stderr_file = None
strcommand = " ".join("'%s'" % x for x in command)
if XPRA_TEST_DEBUG:
Expand All @@ -116,7 +118,7 @@ def run_command(cls, command, env=None, **kwargs):
kwargs["stderr"] = stderr_file
log("stderr=%s for %s", stderr_file.name, strcommand)
try:
proc = subprocess.Popen(args=command, env=env, **kwargs)
proc = subprocess.Popen(args=command, **kwargs)
proc.stdout_file = stdout_file
proc.stderr_file = stderr_file
except OSError as e:
Expand Down Expand Up @@ -246,29 +248,40 @@ def check_start_server(cls, display, *args):

@classmethod
def check_server(cls, subcommand, display, *args):
cmd = [subcommand, display, "--no-daemon"]+list(args)
cmd = [subcommand]
if display:
cmd.append(display)
cmd += ["--no-daemon"]+list(args)
server_proc = cls.run_xpra(cmd)
assert pollwait(server_proc, SERVER_TIMEOUT) is None, "server failed to start with '%s', returned %s" % (cmd, server_proc.poll())
live = cls.dotxpra.displays()
assert display in live, "server display '%s' not found in live displays %s" % (display, live)
if display:
live = cls.dotxpra.displays()
assert display in live, "server display '%s' not found in live displays %s" % (display, live)
#query it:
info = cls.run_xpra(["version", display])
if display:
version = cls.run_xpra(["version", display])
else:
version = cls.run_xpra(["version"])
for _ in range(20):
r = pollwait(info)
r = pollwait(version)
log("version for %s returned %s", display, r)
if r is not None:
if r==1:
continue
break
time.sleep(1)
assert r==0, "version failed for %s, returned %s" % (display, info.poll())
assert r==0, "version failed for %s, returned %s" % (display, version.poll())
return server_proc

@classmethod
def check_stop_server(cls, server_proc, subcommand="stop", display=":99999"):
if server_proc.poll():
return
stopit = cls.run_xpra([subcommand, display])
cmd = [subcommand]
if display:
cmd.append(display)
stopit = cls.run_xpra(cmd)
assert pollwait(stopit) is not None, "%s command failed to exit" % subcommand
assert pollwait(server_proc) is not None, "server process %s failed to exit" % server_proc
assert display not in cls.dotxpra.displays(), "server socket for display %s should have been removed" % display
if display:
assert display not in cls.dotxpra.displays(), "server socket for display %s should have been removed" % display

0 comments on commit ca73769

Please sign in to comment.