From 1c8f3db88212b2f4a5f79122af84f76b2c60da01 Mon Sep 17 00:00:00 2001 Message-Id: <1c8f3db88212b2f4a5f79122af84f76b2c60da01.1713492866.git.mdw@distorted.org.uk> From: Mark Wooding Date: Wed, 21 Nov 2007 09:31:29 +0000 Subject: [PATCH] test to verify current dbversion behavior Organization: Straylight/Edgeware From: Richard Kettlewell --- tests/Makefile.am | 2 +- tests/alltests | 2 +- tests/dbversion.py | 34 ++++++++++++++++++++++++++++++++++ tests/dtest.py | 26 ++++++++++++-------------- tests/files.py | 3 ++- tests/nothing.py | 1 + tests/version.py | 1 + 7 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 tests/dbversion.py diff --git a/tests/Makefile.am b/tests/Makefile.am index 645dd54..8367f65 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -24,4 +24,4 @@ check: topsrcdir=${top_srcdir} \ ${PYTHON} ${srcdir}/alltests -EXTRA_DIST=alltests dtest.py nothing.py version.py +EXTRA_DIST=alltests dtest.py nothing.py version.py dbversion.py diff --git a/tests/alltests b/tests/alltests index 8be9441..a68a3be 100755 --- a/tests/alltests +++ b/tests/alltests @@ -1,7 +1,7 @@ #! /usr/bin/env python import dtest -tests = ["nothing", "version", "files"] +tests = ["nothing", "version", "files", "dbversion"] for test in tests: print "Test '%s'" % test diff --git a/tests/dbversion.py b/tests/dbversion.py new file mode 100644 index 0000000..4e92611 --- /dev/null +++ b/tests/dbversion.py @@ -0,0 +1,34 @@ +#! /usr/bin/env python +import dtest,time,disorder,sys,re + +def test(): + """Database version tests""" + # Start up with dbversion 1 + config = "%s/config" % dtest.testroot + configsave = "%s.save" % config + dtest.copyfile(config, configsave) + open(config, "a").write("dbversion 1\n") + dtest.start_daemon() + time.sleep(2) + dtest.stop_daemon() + # Revert to default configuration + dtest.copyfile(configsave, config) + dtest.start_daemon() + time.sleep(2) + c = disorder.client() + try: + v = c.version() + print "unexpected success" + ok = False + except disorder.communicationError, e: + if re.search("connection refused", str(e)): + print "unexpected error: %s" % e + ok = False + else: + ok = True + dtest.stop_daemon() + if not ok: + sys.exit(1) + +if __name__ == '__main__': + dtest.run(test) diff --git a/tests/dtest.py b/tests/dtest.py index dba7e35..26887cd 100644 --- a/tests/dtest.py +++ b/tests/dtest.py @@ -116,29 +116,24 @@ tracklength *.flac disorder-tracklength copyfile("%s/sounds/scratch.ogg" % topsrcdir, "%s/scratch.ogg" % testroot) -def start_daemon(test): - """start_daemon(TEST) -Start the daemon for test called TEST.""" - global daemon - assert daemon == None - if test == None: - errs = sys.stderr - else: - errs = open("%s.log" % test, "w") +def start_daemon(): + """start_daemon() +Start the daemon.""" + global daemon,errs + assert daemon is None server = None print " starting daemon" daemon = subprocess.Popen(["disorderd", "--foreground", "--config", "%s/config" % testroot], stderr=errs) - disorder._configfile = "%s/config" % testroot - disorder._userconf = False def stop_daemon(): """stop_daemon() Stop the daemon if it has not stopped already""" global daemon + assert daemon is not None rc = daemon.poll() if rc == None: print " stopping daemon" @@ -148,13 +143,15 @@ Stop the daemon if it has not stopped already""" daemon = None def run(test, setup=None, report=True, name=None): - global tests + global tests,errs tests += 1 if setup == None: setup = stdtracks + errs = open("%s.log" % test.__name__, "w") # HNGGGH. nO. + disorder._configfile = "%s/config" % testroot + disorder._userconf = False common_setup() setup() - start_daemon(name) try: try: test() @@ -163,7 +160,8 @@ def run(test, setup=None, report=True, name=None): failures += 1 print e finally: - stop_daemon() + if daemon is not None: + stop_daemon() if report: if failures: print " FAILED" diff --git a/tests/files.py b/tests/files.py index 938564a..e0237d4 100755 --- a/tests/files.py +++ b/tests/files.py @@ -2,7 +2,8 @@ import dtest,time,disorder,sys def test(): - """Ask the server its version number""" + """Check that the file listing comes out right""" + dtest.start_daemon() time.sleep(5) # give rescan a chance c = disorder.client() failures = 0 diff --git a/tests/nothing.py b/tests/nothing.py index 7a8e55d..70e481b 100755 --- a/tests/nothing.py +++ b/tests/nothing.py @@ -3,6 +3,7 @@ import dtest,time def test(): """Just start the server and then stop it a few seconds later""" + dtest.start_daemon() time.sleep(2) if __name__ == '__main__': diff --git a/tests/version.py b/tests/version.py index 3566867..7a95573 100755 --- a/tests/version.py +++ b/tests/version.py @@ -3,6 +3,7 @@ import dtest,time,disorder def test(): """Ask the server its version number""" + dtest.start_daemon() time.sleep(2) # give the daemon a chance to start up c = disorder.client() v = c.version() -- [mdw]