Home | History | Annotate | Download | only in controllers
      1 # Copyright (C) 2010 Google Inc. All rights reserved.
      2 # Copyright (C) 2010 Gabor Rapcsanyi (rgabor (at] inf.u-szeged.hu), University of Szeged
      3 #
      4 # Redistribution and use in source and binary forms, with or without
      5 # modification, are permitted provided that the following conditions are
      6 # met:
      7 #
      8 #     * Redistributions of source code must retain the above copyright
      9 # notice, this list of conditions and the following disclaimer.
     10 #     * Redistributions in binary form must reproduce the above
     11 # copyright notice, this list of conditions and the following disclaimer
     12 # in the documentation and/or other materials provided with the
     13 # distribution.
     14 #     * Neither the name of Google Inc. nor the names of its
     15 # contributors may be used to endorse or promote products derived from
     16 # this software without specific prior written permission.
     17 #
     18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 
     30 """Unit tests for manager.py."""
     31 
     32 import sys
     33 import time
     34 import webkitpy.thirdparty.unittest2 as unittest
     35 
     36 from webkitpy.common.host_mock import MockHost
     37 from webkitpy.layout_tests.controllers.manager import Manager
     38 from webkitpy.layout_tests.models import test_expectations
     39 from webkitpy.layout_tests.models.test_run_results import TestRunResults
     40 from webkitpy.thirdparty.mock import Mock
     41 from webkitpy.tool.mocktool import MockOptions
     42 
     43 
     44 class ManagerTest(unittest.TestCase):
     45     def test_needs_servers(self):
     46         def get_manager():
     47             port = Mock()  # FIXME: Use a tighter mock.
     48             port.TEST_PATH_SEPARATOR = '/'
     49             manager = Manager(port, options=MockOptions(http=True, max_locked_shards=1), printer=Mock())
     50             return manager
     51 
     52         manager = get_manager()
     53         self.assertFalse(manager.needs_servers(['fast/html']))
     54 
     55         manager = get_manager()
     56         self.assertTrue(manager.needs_servers(['http/tests/misc']))
     57 
     58     def test_servers_started(self):
     59         def get_manager(port):
     60             manager = Manager(port, options=MockOptions(http=True, max_locked_shards=1), printer=Mock())
     61             return manager
     62 
     63         def start_http_server(number_of_servers=None):
     64             self.http_started = True
     65 
     66         def start_websocket_server():
     67             self.websocket_started = True
     68 
     69         def stop_http_server():
     70             self.http_stopped = True
     71 
     72         def stop_websocket_server():
     73             self.websocket_stopped = True
     74 
     75         host = MockHost()
     76         port = host.port_factory.get('test-mac-leopard')
     77         port.start_http_server = start_http_server
     78         port.start_websocket_server = start_websocket_server
     79         port.stop_http_server = stop_http_server
     80         port.stop_websocket_server = stop_websocket_server
     81 
     82         self.http_started = self.http_stopped = self.websocket_started = self.websocket_stopped = False
     83         manager = get_manager(port)
     84         manager._start_servers(['http/tests/foo.html'])
     85         self.assertEqual(self.http_started, True)
     86         self.assertEqual(self.websocket_started, False)
     87         manager._stop_servers()
     88         self.assertEqual(self.http_stopped, True)
     89         self.assertEqual(self.websocket_stopped, False)
     90 
     91         self.http_started = self.http_stopped = self.websocket_started = self.websocket_stopped = False
     92         manager._start_servers(['http/tests/websocket/foo.html'])
     93         self.assertEqual(self.http_started, True)
     94         self.assertEqual(self.websocket_started, True)
     95         manager._stop_servers()
     96         self.assertEqual(self.http_stopped, True)
     97         self.assertEqual(self.websocket_stopped, True)
     98 
     99         self.http_started = self.http_stopped = self.websocket_started = self.websocket_stopped = False
    100         manager._start_servers(['fast/html/foo.html'])
    101         self.assertEqual(self.http_started, False)
    102         self.assertEqual(self.websocket_started, False)
    103         manager._stop_servers()
    104         self.assertEqual(self.http_stopped, False)
    105         self.assertEqual(self.websocket_stopped, False)
    106 
    107 
    108     def test_look_for_new_crash_logs(self):
    109         def get_manager():
    110             host = MockHost()
    111             port = host.port_factory.get('test-mac-leopard')
    112             manager = Manager(port, options=MockOptions(test_list=None, http=True, max_locked_shards=1), printer=Mock())
    113             return manager
    114         host = MockHost()
    115         port = host.port_factory.get('test-mac-leopard')
    116         tests = ['failures/expected/crash.html']
    117         expectations = test_expectations.TestExpectations(port, tests)
    118         run_results = TestRunResults(expectations, len(tests))
    119         manager = get_manager()
    120         manager._look_for_new_crash_logs(run_results, time.time())
    121