diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2013-04-26 14:52:33 +0200 |
---|---|---|
committer | Patrick Ohly <patrick.ohly@intel.com> | 2013-05-13 17:49:50 +0200 |
commit | 60f7ccda876c06614b6a416dcb882f06701ee6bb (patch) | |
tree | 4f1a117d54162ec1f7cc6e8509cb7cf8728ad9f8 | |
parent | 59f2c2b101f7ed1d4edf0aaf40896c091f3470fc (diff) |
D-Bus testing: abort server with background thread
Ensure that server is currently waiting for background thread, then
abort via Session.Abort(). Needs to be detected by backend and the
lead to normal session shutdown.
-rwxr-xr-x | test/test-dbus.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/test-dbus.py b/test/test-dbus.py index 9af8bfd7..276e45df 100755 --- a/test/test-dbus.py +++ b/test/test-dbus.py @@ -9163,6 +9163,55 @@ class TestHTTP(CmdlineUtil, unittest.TestCase): self.assertEqual(err, None) self.assertEqual(0, code) + @timeout(200) + @property("ENV", "SYNCEVOLUTION_FILE_SOURCE_DELAY_OPEN_addressbook-slow-server=400") + def testAbortThread(self): + """TestHTTP.testAbortThread - slow down server in open, abort sync while waiting for background thread""" + port = self.runHTTPServer() + self.setUpConfigs(port, slowServer=True, requestMaxTime=200) + self.session = None + self.isWaiting = False + self.messages = [] + def output(path, level, message, process): + self.messages.append(message) + if 'wait for background thread: ' in message: + self.isWaiting = True + signal = bus.add_signal_receiver(output, + 'LogOutput', + 'org.syncevolution.Server', + self.server.bus_name, + None, + byte_arrays=True, + utf8_strings=True) + + s = self.startCmdline(["--sync", "slow", "--daemon=no", "client"], + preserveOutputOrder=True) + + # Wait for session... + while not self.session: + self.loopIteration('waiting for session', may_block=True) + # ... and the confirmation that the background thread is running. + while not self.isWaiting: + self.loopIteration('background thread', may_block=True) + + # We need to abort syncevo-dbus-server. Aborting the client via SIGTERM + # would not abort the server. + self.session.Abort(timeout=self.dbusTimeout) + + # The HTTP client should see a network error. + out, err, code = self.finishCmdline(s, expectSuccess=False, sessionFlags=None) + self.assertEqual(err, None) + self.assertEqual(1, code) + self.assertIn('external transport failure', out) + + # We expect that the FileSyncSource::open() detects the abort + # request quickly and then let's the background thread be + # reaped normally by the master thread. + self.assertIn('background thread completed', self.messages) + + # Finally, also check server session status. + status, error, sources = self.session.GetStatus(timeout=self.dbusTimeout) + self.assertEqual(('done', 20017), (status, error)) if __name__ == '__main__': unittest.main() |