summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2012-05-09 11:42:54 +0200
committerPatrick Ohly <patrick.ohly@intel.com>2012-05-10 22:08:50 +0200
commit9fad2cb9a318e57d99f26623cbe6b3fd429541ac (patch)
tree36c32970da30b53215395ad5d883f2382e2b277a
parente2893aa1e530a90bbe291d9d0e5774420162dde0 (diff)
D-Bus testing: enhanced testParentFailure
Use the new getChildren() to check for children, instead of relying on ps. Wait for syncevo-dbus-server, to avoid race conditions between signal() and waitpid(). Check status and error message in the sync report written by syncevo-dbus-helper.
-rwxr-xr-xtest/test-dbus.py54
1 files changed, 30 insertions, 24 deletions
diff --git a/test/test-dbus.py b/test/test-dbus.py
index e4e9922d..61ad324f 100755
--- a/test/test-dbus.py
+++ b/test/test-dbus.py
@@ -30,6 +30,8 @@ import heapq
import string
import difflib
import traceback
+import ConfigParser
+import io
import dbus
from dbus.mainloop.glib import DBusGMainLoop
@@ -1011,6 +1013,18 @@ status: idle, 0, {}
lines.append(event[0])
return '\n'.join(lines)
+ def assertSyncStatus(self, config, status, error):
+ cache = self.own_xdg and os.path.join(xdg_root, 'cache', 'syncevolution') or \
+ os.path.join(os.environ['HOME'], '.cache', 'syncevolution')
+ entries = [x for x in os.listdir(cache) if x.startswith(config + '-')]
+ entries.sort()
+ self.assertEqual(1, len(entries))
+ config = ConfigParser.ConfigParser()
+ content = '[fake]\n' + open(os.path.join(cache, entries[0], 'status.ini')).read()
+ config.readfp(io.BytesIO(content))
+ self.assertEqual(status, config.getint('fake', 'status'))
+ self.assertEqual(error, config.get('fake', 'error'))
+
def doCheckSync(self, expectedError=0, expectedResult=0, reportOptional=False, numReports=1):
# check recorded events in DBusUtil.events, first filter them
statuses = []
@@ -3609,38 +3623,30 @@ END:VCARD''')
finally:
dbusSignal.remove()
+ # Give syncevo-dbus-helper and syncevo-local-sync some time to shut down.
+ time.sleep(usingValgrind() and 60 or 10)
+
# Remove syncevo-dbus-server zombie process(es).
+ DBusUtil.pserver.wait()
+ DBusUtil.pserver = None
try:
- while os.waitpid(-1, os.WNOHANG)[0]:
- pass
+ while True:
+ res = os.waitpid(-1, os.WNOHANG)
+ if res[0]:
+ logging.printf('got status %d for pid %d', res[1], res[0])
+ else:
+ break
except OSError, ex:
if ex.errno != errno.ECHILD:
raise ex
- DBusUtil.pserver = None
-
- # Give syncevo-dbus-helper and syncevo-local-sync some time to shut down.
- time.sleep(usingValgrind() and 60 or 10)
# Now no processes should be left in the process group
# of the syncevo-dbus-server.
- ps = subprocess.Popen(['ps', 'x', '--no-headers', '-o', 'pgid,pid,args'],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- out, err = ps.communicate()
- self.assertEqual('', err)
- children = []
- for line in out.splitlines():
- pgid, command = line.lstrip().split(' ', 1)
- if int(pgid) == pid:
- children.append(command)
- self.assertEqual([], children)
-
- # try:
- # os.kill(-pid, signal.SIGTERM)
- # self.fail('found some unexpected child process of syncevo-dbus-server')
- # except OSError, ex:
- # if ex.errno != errno.ECHILD:
- # raise ex
+ self.assertEqual({}, self.getChildren())
+
+ # Sync should have failed with an explanation that it was
+ # because of the password.
+ self.assertSyncStatus('server', 22003, "error code from SyncEvolution password request timed out (local, status 22003): failure in local sync child: Could not get the 'addressbook backend' password from user.")
# TODO: test that password timeout and password cancelation are
# correctly recognized during a sync