chiark / gitweb /
Arrange for some tests to block until the first rescan has completed,
authorRichard Kettlewell <rjk@greenend.org.uk>
Thu, 6 Mar 2008 20:45:33 +0000 (20:45 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Thu, 6 Mar 2008 20:45:33 +0000 (20:45 +0000)
as otherwise they will fail spuriously on slower systems.

python/disorder.py.in
tests/dbversion.py
tests/dtest.py
tests/dump.py
tests/files.py

index 8fe7d21ec0d69dc53ccab45a0680f1162a414918..595ee9254ea324cbbc0272a4e0f73d9bd2cdfe04 100644 (file)
@@ -1,5 +1,5 @@
 #
 #
-# Copyright (C) 2004, 2005, 2007 Richard Kettlewell
+# Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -479,15 +479,12 @@ class client:
     """
     self._simple("reconfigure")
 
     """
     self._simple("reconfigure")
 
-  def rescan(self, pattern):
+  def rescan(self):
     """Rescan one or more collections.
 
     """Rescan one or more collections.
 
-    Arguments:
-    pattern -- glob pattern matching collections to rescan.
-
     Only trusted users can perform this operation.
     """
     Only trusted users can perform this operation.
     """
-    self._simple("rescan", pattern)
+    self._simple("rescan")
 
   def version(self):
     """Return the server's version number."""
 
   def version(self):
     """Return the server's version number."""
@@ -1100,6 +1097,8 @@ class monitor:
     elif keyword == 'scratched':
       if len(bits) == 2:
         return self.scratched(bits[0], bits[1])
     elif keyword == 'scratched':
       if len(bits) == 2:
         return self.scratched(bits[0], bits[1])
+    elif keyword == 'rescanned':
+      return self.rescanned()
     return self.invalid(line)
 
   def completed(self, track):
     return self.invalid(line)
 
   def completed(self, track):
@@ -1179,6 +1178,10 @@ class monitor:
     line -- line that could not be understood"""
     return True
 
     line -- line that could not be understood"""
     return True
 
+  def rescanned(self):
+    """Called when a rescan completes"""
+    return True
+
 # Local Variables:
 # mode:python
 # py-indent-offset:2
 # Local Variables:
 # mode:python
 # py-indent-offset:2
index 4ae71d7a81c479fee5643720eb3079438c0bae29..218e0c9023056442f3cad13539c2859e5fb185c9 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 #
 # This file is part of DisOrder.
 #! /usr/bin/env python
 #
 # This file is part of DisOrder.
-# Copyright (C) 2007 Richard Kettlewell
+# Copyright (C) 2007, 2008 Richard Kettlewell
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -29,6 +29,7 @@ def test():
     open(config, "a").write("dbversion 1\n")
     dtest.start_daemon()
     dtest.create_user()
     open(config, "a").write("dbversion 1\n")
     dtest.start_daemon()
     dtest.create_user()
+    dtest.rescan()
     dtest.stop_daemon()
     # Revert to default configuration
     dtest.copyfile(configsave, config)
     dtest.stop_daemon()
     # Revert to default configuration
     dtest.copyfile(configsave, config)
index 982f4d499d07a9ff44305659886da51bd558e329..6a275a890bb0a6fbebd1b6cd70530c0a4a3137f0 100644 (file)
@@ -1,7 +1,7 @@
 #-*-python-*-
 #
 # This file is part of DisOrder.
 #-*-python-*-
 #
 # This file is part of DisOrder.
-# Copyright (C) 2007 Richard Kettlewell
+# Copyright (C) 2007 ,2008 Richard Kettlewell
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -269,6 +269,19 @@ def create_user(username="fred", password="fredpass"):
              "--config", disorder._configfile, "--no-per-user-config",
              "--user", "root", "edituser", username, "rights", "all"])
 
              "--config", disorder._configfile, "--no-per-user-config",
              "--user", "root", "edituser", username, "rights", "all"])
 
+def rescan(c=None):
+    class rescan_monitor(disorder.monitor):
+        def rescanned(self):
+            return False
+    if c is None:
+        c = disorder.client()
+    m = rescan_monitor()
+    print " initiating rescan"
+    c.rescan()
+    print " waiting for rescan to complete"
+    m.run()
+    print " rescan completed"
+
 def stop_daemon():
     """stop_daemon()
 
 def stop_daemon():
     """stop_daemon()
 
@@ -353,28 +366,30 @@ def lists_have_same_contents(l1, l2):
     s2 = []
     s2.extend(l2)
     s2.sort()
     s2 = []
     s2.extend(l2)
     s2.sort()
-    return s1 == s2
+    return map(nfc, s1) == map(nfc, s2)
 
 
-def check_files():
+def check_files(chatty=True):
     c = disorder.client()
     failures = 0
     for d in dirs_by_dir:
         xdirs = dirs_by_dir[d]
         dirs = c.directories(d)
         if not lists_have_same_contents(xdirs, dirs):
     c = disorder.client()
     failures = 0
     for d in dirs_by_dir:
         xdirs = dirs_by_dir[d]
         dirs = c.directories(d)
         if not lists_have_same_contents(xdirs, dirs):
-            print
-            print "directory: %s" % d
-            print "expected:  %s" % xdirs
-            print "got:       %s" % dirs
+            if chatty:
+                print
+                print "directory: %s" % d
+                print "expected:  %s" % xdirs
+                print "got:       %s" % dirs
             failures += 1
     for d in files_by_dir:
         xfiles = files_by_dir[d]
         files = c.files(d)
         if not lists_have_same_contents(xfiles, files):
             failures += 1
     for d in files_by_dir:
         xfiles = files_by_dir[d]
         files = c.files(d)
         if not lists_have_same_contents(xfiles, files):
-            print
-            print "directory: %s" % d
-            print "expected:  %s" % xfiles
-            print "got:       %s" % files
+            if chatty:
+                print
+                print "directory: %s" % d
+                print "expected:  %s" % xfiles
+                print "got:       %s" % files
             failures += 1
     return failures
 
             failures += 1
     return failures
 
index 507199a10e33c4287807b91b4a7f08dc66ea8dda..ff28a0ffc32001c3187f723dbd546f22e4a1dd41 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 #
 # This file is part of DisOrder.
 #! /usr/bin/env python
 #
 # This file is part of DisOrder.
-# Copyright (C) 2007 Richard Kettlewell
+# Copyright (C) 2007, 2008 Richard Kettlewell
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@ def test():
     """Exercise database dumper"""
     dtest.start_daemon()
     dtest.create_user()
     """Exercise database dumper"""
     dtest.start_daemon()
     dtest.create_user()
+    dtest.rescan()
     c = disorder.client()
     track = "%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks
     dump = "%s/dumpfile" % dtest.testroot
     c = disorder.client()
     track = "%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks
     dump = "%s/dumpfile" % dtest.testroot
index a41937fd2e6ccdb2ddb420942099906710a9c415..984c6cca89dd839d05e26f10112aada72b96a592 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 #
 # This file is part of DisOrder.
 #! /usr/bin/env python
 #
 # This file is part of DisOrder.
-# Copyright (C) 2007 Richard Kettlewell
+# Copyright (C) 2007, 2008 Richard Kettlewell
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@ def test():
     """Check that the file listing comes out right"""
     dtest.start_daemon()
     dtest.create_user()
     """Check that the file listing comes out right"""
     dtest.start_daemon()
     dtest.create_user()
+    dtest.rescan()
     assert dtest.check_files() == 0, "dtest.check_files"
     print " checking regexp file listing"
     c = disorder.client()
     assert dtest.check_files() == 0, "dtest.check_files"
     print " checking regexp file listing"
     c = disorder.client()