chiark / gitweb /
test to verify current dbversion behavior
authorRichard Kettlewell <rjk@greenend.org.uk>
Wed, 21 Nov 2007 09:31:29 +0000 (09:31 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Wed, 21 Nov 2007 09:31:29 +0000 (09:31 +0000)
tests/Makefile.am
tests/alltests
tests/dbversion.py [new file with mode: 0644]
tests/dtest.py
tests/files.py
tests/nothing.py
tests/version.py

index 645dd54..8367f65 100644 (file)
@@ -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
index 8be9441..a68a3be 100755 (executable)
@@ -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 (file)
index 0000000..4e92611
--- /dev/null
@@ -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)
index dba7e35..26887cd 100644 (file)
@@ -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"
index 938564a..e0237d4 100755 (executable)
@@ -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
index 7a8e55d..70e481b 100755 (executable)
@@ -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__':
index 3566867..7a95573 100755 (executable)
@@ -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()