~stephen-xemacs/mailman/maxking

« back to all changes in this revision

Viewing changes to src/mailman/runners/tests/test_rest.py

  • Committer: Barry Warsaw
  • Date: 2013-06-17 13:36:43 UTC
  • Revision ID: barry@list.org-20130617133643-uj7atdykh2whwabw
 * `bin/runner` command has been simplified and its command line options
   reduced.  Now, only one `-r/--runner` option may be provided and the
   round-robin feature has been removed.
 * Fixed REST server crash on `reopen` command.  Identification and test
   provided by Aurélien Bompard.  (LP: #1184376)

Also:

 * bin/runner now uses standard argparse instead of ScriptOptions.
 * The entire bin/runner machinery has bee reorganized and simplified.  There
 * is no more Loop class.  Signal setting is moved directly into the base
   Runner class and overrided in specific subclasses (e.g. RESTRunner which
   must cleanly shutdown its TCPServer).  The runner exit status is now set
   directly on the Runner instance.
 * Fixed a few minor style issues.
 * In order to cleanly shutdown the RESTRunner's WSGI server, we must start a
   subthread which only watches for an Event and then calls the server's
   shutdown() method.  It has to be this way because the WSGI server itself
   (due to interactions with SQLite), and the signal handlers (due to Python's
   signal handling semantics) must both run in the main thread.  However, the
   shutdown() must be invoked from a subthread in order to prevent deadlock.
 * Refactor the RESTLayer to eliminate duplication of code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2013 by the Free Software Foundation, Inc.
 
2
#
 
3
# This file is part of GNU Mailman.
 
4
#
 
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
 
6
# the terms of the GNU General Public License as published by the Free
 
7
# Software Foundation, either version 3 of the License, or (at your option)
 
8
# any later version.
 
9
#
 
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
 
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
13
# more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License along with
 
16
# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
"""Test the REST runner."""
 
19
 
 
20
from __future__ import absolute_import, print_function, unicode_literals
 
21
 
 
22
__metaclass__ = type
 
23
__all__ = [
 
24
    'TestRESTRunner',
 
25
    ]
 
26
 
 
27
 
 
28
import os
 
29
import signal
 
30
import unittest
 
31
 
 
32
from mailman.testing.helpers import call_api, wait_for_webservice
 
33
from mailman.testing.layers import RESTLayer
 
34
 
 
35
 
 
36
 
 
37
class TestRESTRunner(unittest.TestCase):
 
38
    """Test the REST runner."""
 
39
 
 
40
    layer = RESTLayer
 
41
 
 
42
    def test_sighup_restart(self):
 
43
        # The REST runner must survive a SIGHUP.
 
44
        wait_for_webservice()
 
45
        for pid in self.layer.server.runner_pids:
 
46
            os.kill(pid, signal.SIGHUP)
 
47
        wait_for_webservice()
 
48
        # This should not raise an exception.  The best way to assert this is
 
49
        # to ensure that the response is valid.
 
50
        response, json = call_api('http://localhost:9001/3.0/system')
 
51
        self.assertEqual(json['content-location'],
 
52
                         'http://localhost:9001/3.0/system')