示例#1
0
def test_session_02(tmp_path, mocker):
    """test Session.generate_testcase()"""
    Status.PATH = str(tmp_path)
    fake_server = mocker.patch("sapphire.Sapphire", autospec=True)
    mocker.patch("grizzly.session.TestFile", autospec=True)
    fake_adapter = mocker.Mock(spec=Adapter)
    fake_iomgr = mocker.Mock(spec=IOManager)
    fake_iomgr.active_input = mocker.Mock(spec=InputFile)
    fake_iomgr.active_input.file_name = "infile"
    fake_iomgr.create_testcase.return_value = mocker.Mock(spec=TestCase)
    fake_iomgr.server_map = mocker.Mock(spec=ServerMap)
    fake_iomgr.server_map.includes = []
    fake_iomgr.server_map.redirects = []
    fake_iomgr.server_map.dynamic_responses = []
    fake_iomgr.server_map.redirects = ({
        "url": "",
        "file_name": "somefile",
        "required": True
    }, )
    fake_target = mocker.Mock(spec=Target)
    fake_target.prefs = "fake_prefs.js"

    session = Session(fake_adapter, False, [], fake_iomgr, None, fake_target)
    session.config_server(5)
    fake_adapter.generate.assert_not_called()
    testcase = session.generate_testcase()
    assert fake_adapter.generate.call_count == 1
    assert testcase.add_meta.call_count == 1
    assert fake_server.return_value.set_redirect.call_count == 1
示例#2
0
def test_session_06(tmp_path, mocker):
    """test Session.run()"""
    Status.PATH = str(tmp_path)
    fake_server = mocker.patch("sapphire.Sapphire", autospec=True)
    mocker.patch("grizzly.session.TestFile", autospec=True)
    fake_adapter = mocker.Mock(spec=Adapter)
    fake_adapter.IGNORE_UNSERVED = True
    fake_adapter.ROTATION_PERIOD = 2
    fake_adapter.TEST_DURATION = 10
    fake_iomgr = mocker.Mock(spec=IOManager)
    fake_iomgr.server_map = mocker.Mock(spec=ServerMap)
    fake_iomgr.server_map.includes = []
    fake_iomgr.server_map.redirects = []
    fake_iomgr.server_map.dynamic_responses = []
    fake_iomgr.active_input = mocker.Mock(spec=InputFile)
    fake_iomgr.active_input.file_name = "input.txt"
    fake_iomgr.create_testcase.return_value = mocker.Mock(spec=TestCase)
    fake_iomgr.harness = None
    fake_iomgr.input_files = []
    fake_iomgr.landing_page.return_value = "HOMEPAGE.HTM"
    fake_iomgr.tests = mocker.Mock(spec=list)
    fake_iomgr.tests.pop.return_value = mocker.Mock(spec=TestCase)
    fake_iomgr.working_path = str(tmp_path)
    fake_reporter = mocker.Mock(spec=Reporter)
    fake_target = mocker.Mock(spec=Target)
    fake_target.rl_reset = 5
    fake_target.log_size.return_value = 1000
    fake_target.prefs = "prefs.js"

    session = Session(fake_adapter, False, [], fake_iomgr, fake_reporter,
                      fake_target)
    session.TARGET_LOG_SIZE_WARN = 100
    session.config_server(5)
    session._lol = mocker.Mock(spec=LogOutputLimiter)

    def fake_serve_testcase(*_a, **_kw):
        return SERVED_TIMEOUT if session.status.iteration % 2 else SERVED_ALL, []

    session.server.serve_testcase = fake_serve_testcase
    fake_adapter.on_served.assert_not_called()
    fake_adapter.on_timeout.assert_not_called()
    fake_adapter.pre_launch.assert_not_called()
    session.run(10)
    assert fake_adapter.on_served.call_count == 5
    assert fake_adapter.on_timeout.call_count == 5
    assert fake_adapter.pre_launch.call_count == 10
    assert fake_iomgr.purge_tests.call_count == 10
    assert fake_target.launch.call_count == fake_iomgr.purge_tests.call_count
    session.close()

    assert fake_server.call_count == 1
    assert fake_server.return_value.close.call_count == 1
    assert session.status.iteration == 10
    assert fake_iomgr.create_testcase.call_count == 10
    assert fake_target.detect_failure.call_count == 10
    assert fake_iomgr.create_testcase.return_value.purge_optional.call_count == 10
示例#3
0
def test_session_05(tmp_path, mocker):
    """test Session.config_server()"""
    Status.PATH = str(tmp_path)
    fake_adapter = mocker.Mock(spec=Adapter)
    mocker.patch("sapphire.Sapphire", autospec=True)
    fake_iomgr = mocker.Mock(spec=IOManager)
    fake_iomgr.server_map = mocker.Mock(spec=ServerMap)
    session = Session(fake_adapter, False, [], fake_iomgr, None,
                      mocker.Mock(spec=Target))
    session.config_server(5)
    assert fake_iomgr.server_map.set_dynamic_response.call_count == 1
示例#4
0
def test_session_00(tmp_path, mocker):
    """test basic Session functions"""
    Status.PATH = str(tmp_path)
    fake_server = mocker.patch("sapphire.Sapphire", autospec=True)
    fake_server.return_value.serve_testcase.return_value = (SERVED_TIMEOUT, [])
    mocker.patch("grizzly.session.TestFile", autospec=True)
    fake_adapter = mocker.Mock(spec=Adapter)
    fake_adapter.TEST_DURATION = 10
    fake_adapter.ROTATION_PERIOD = 0
    fake_iomgr = mocker.Mock(spec=IOManager)
    fake_iomgr.server_map = mocker.Mock(spec=ServerMap)
    fake_iomgr.server_map.includes = []
    fake_iomgr.server_map.redirects = []
    fake_iomgr.server_map.dynamic_responses = []
    fake_iomgr.active_input = mocker.Mock(spec=InputFile)
    fake_iomgr.active_input.file_name = "input.txt"
    fake_iomgr.create_testcase.return_value = mocker.Mock(spec=TestCase)
    fake_iomgr.harness = None
    fake_iomgr.input_files = []
    fake_iomgr.landing_page.return_value = "HOMEPAGE.HTM"
    fake_iomgr.tests = [mocker.Mock(spec=TestCase)]
    fake_iomgr.working_path = str(tmp_path)
    fake_reporter = mocker.Mock(spec=Reporter)
    fake_target = mocker.Mock(spec=Target)
    fake_target.log_size.return_value = 1000
    fake_target.rl_reset = 10
    fake_target.prefs = None

    session = Session(fake_adapter, False, [], fake_iomgr, fake_reporter,
                      fake_target)
    session.TARGET_LOG_SIZE_WARN = 100
    session.coverage = True
    session.config_server(5)
    session.run()
    session.close()

    assert fake_iomgr.create_testcase.call_count == 1
    assert fake_server.call_count == 1
    assert fake_server.return_value.serve_testcase.call_count == 1
    assert fake_server.return_value.close.call_count == 1
    assert fake_target.detect_failure.call_count == 1
示例#5
0
def test_session_05(tmp_path, mocker):
    """test Session.config_server()"""
    Status.PATH = str(tmp_path)
    fake_adapter = mocker.Mock(spec=Adapter)
    fake_server = mocker.patch("sapphire.Sapphire", autospec=True)
    fake_iomgr = mocker.Mock(spec=IOManager)
    fake_iomgr.server_map = mocker.Mock(spec=ServerMap)
    fake_iomgr.server_map.includes = [("test", "test")]
    fake_iomgr.server_map.dynamic_responses = [{
        "url": "a",
        "callback": lambda: 1,
        "mime": "x"
    }]
    fake_iomgr.server_map.redirects = [{
        "url": "",
        "file_name": "somefile",
        "required": True
    }]
    session = Session(fake_adapter, False, [], fake_iomgr, None,
                      mocker.Mock(spec=Target))
    session.config_server(5)
    assert fake_server.return_value.add_dynamic_response.call_count == 2
    assert fake_server.return_value.add_include.call_count == 1