From d8055dc4411375d23b136cd51f4bed9da445ec93 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Thu, 6 Mar 2008 20:45:33 +0000 Subject: [PATCH] Arrange for some tests to block until the first rescan has completed, as otherwise they will fail spuriously on slower systems. Organization: Straylight/Edgeware From: Richard Kettlewell --- python/disorder.py.in | 15 +++++++++------ tests/dbversion.py | 3 ++- tests/dtest.py | 37 ++++++++++++++++++++++++++----------- tests/dump.py | 3 ++- tests/files.py | 3 ++- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/python/disorder.py.in b/python/disorder.py.in index 8fe7d21..595ee92 100644 --- a/python/disorder.py.in +++ b/python/disorder.py.in @@ -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 @@ -479,15 +479,12 @@ class client: """ self._simple("reconfigure") - def rescan(self, pattern): + def rescan(self): """Rescan one or more collections. - Arguments: - pattern -- glob pattern matching collections to rescan. - Only trusted users can perform this operation. """ - self._simple("rescan", pattern) + self._simple("rescan") 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 == 'rescanned': + return self.rescanned() return self.invalid(line) def completed(self, track): @@ -1179,6 +1178,10 @@ class monitor: 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 diff --git a/tests/dbversion.py b/tests/dbversion.py index 4ae71d7..218e0c9 100755 --- a/tests/dbversion.py +++ b/tests/dbversion.py @@ -1,7 +1,7 @@ #! /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 @@ -29,6 +29,7 @@ def test(): 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) diff --git a/tests/dtest.py b/tests/dtest.py index 982f4d4..6a275a8 100644 --- a/tests/dtest.py +++ b/tests/dtest.py @@ -1,7 +1,7 @@ #-*-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 @@ -269,6 +269,19 @@ def create_user(username="fred", password="fredpass"): "--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() @@ -353,28 +366,30 @@ def lists_have_same_contents(l1, l2): 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): - 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): - 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 diff --git a/tests/dump.py b/tests/dump.py index 507199a..ff28a0f 100755 --- a/tests/dump.py +++ b/tests/dump.py @@ -1,7 +1,7 @@ #! /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 @@ -24,6 +24,7 @@ def test(): """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 diff --git a/tests/files.py b/tests/files.py index a41937f..984c6cc 100755 --- a/tests/files.py +++ b/tests/files.py @@ -1,7 +1,7 @@ #! /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 @@ -24,6 +24,7 @@ def test(): """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() -- [mdw]