Exemplo n.º 1
0
async def test_start_search_multiqueue(ladder_service: LadderService,
                                       player_factory, queue_factory,
                                       event_loop):
    ladder_service.queues["tmm2v2"] = queue_factory("tmm2v2")

    p1 = player_factory("Dostya",
                        ladder_rating=(1000, 10),
                        with_lobby_connection=True)

    ladder_service.start_search([p1], "ladder1v1")
    await exhaust_callbacks(event_loop)

    assert "ladder1v1" in ladder_service._searches[p1]

    ladder_service.start_search([p1], "tmm2v2")
    await exhaust_callbacks(event_loop)

    assert "ladder1v1" in ladder_service._searches[p1]
    assert "tmm2v2" in ladder_service._searches[p1]

    ladder_service.cancel_search(p1, "tmm2v2")
    await exhaust_callbacks(event_loop)

    assert "ladder1v1" in ladder_service._searches[p1]
    assert "tmm2v2" not in ladder_service._searches[p1]
Exemplo n.º 2
0
async def test_search_info_message(ladder_service: LadderService,
                                   player_factory, queue_factory, event_loop):
    ladder_service.queues["tmm2v2"] = queue_factory("tmm2v2")

    p1 = player_factory("Dostya",
                        player_id=1,
                        ladder_rating=(1000, 10),
                        with_lobby_connection=True)
    p1.write_message = CoroutineMock()
    p2 = player_factory("Rhiza",
                        player_id=2,
                        ladder_rating=(1000, 10),
                        with_lobby_connection=True)
    p2.write_message = CoroutineMock()

    ladder_service.start_search([p1, p2], "ladder1v1")
    await exhaust_callbacks(event_loop)

    msg = {
        "command": "search_info",
        "queue_name": "ladder1v1",
        "state": "start"
    }
    p1.write_message.assert_called_once_with(msg)
    p2.write_message.assert_called_once_with(msg)

    p1.write_message.reset_mock()
    p2.write_message.reset_mock()

    ladder_service.start_search([p1, p2], "tmm2v2")
    await exhaust_callbacks(event_loop)

    msg = {"command": "search_info", "queue_name": "tmm2v2", "state": "start"}
    p1.write_message.assert_called_once_with(msg)
    p2.write_message.assert_called_once_with(msg)

    p1.write_message.reset_mock()
    p2.write_message.reset_mock()
    ladder_service.cancel_search(p1)
    await exhaust_callbacks(event_loop)

    call_args = [
        mock.call({
            "command": "search_info",
            "queue_name": "ladder1v1",
            "state": "stop"
        }),
        mock.call({
            "command": "search_info",
            "queue_name": "tmm2v2",
            "state": "stop"
        }),
    ]

    assert p1.write_message.call_args_list == call_args
    assert p2.write_message.call_args_list == call_args
Exemplo n.º 3
0
async def test_cancel_all_searches(ladder_service: LadderService,
                                   player_factory, event_loop):
    p1 = player_factory(login="******", player_id=1, ladder_rating=(1500, 500), ladder_games=0)

    ladder_service.start_search([p1], "ladder1v1")
    await exhaust_callbacks(event_loop)
    search = ladder_service._searches[p1]["ladder1v1"]

    assert p1.state == PlayerState.SEARCHING_LADDER
    assert search in ladder_service.queues["ladder1v1"]._queue
    assert not search.is_cancelled

    ladder_service.cancel_search(p1)

    assert p1.state == PlayerState.IDLE
    assert search.is_cancelled
    assert "ladder1v1" not in ladder_service._searches[p1]
Exemplo n.º 4
0
async def test_start_and_cancel_search(ladder_service: LadderService):
    p1 = mock.create_autospec(Player('Dostya', id=1))
    p1.ladder_rating = (1500, 500)
    p1.numGames = 0

    search = Search([p1])

    ladder_service.start_search(p1, search, 'ladder1v1')
    await asyncio.sleep(0)  # Give the other coro a chance to run

    assert p1.state == PlayerState.SEARCHING_LADDER
    assert ladder_service.queues['ladder1v1'].queue[search]
    assert not search.is_cancelled

    ladder_service.cancel_search(p1)

    assert p1.state == PlayerState.IDLE
    assert search.is_cancelled
Exemplo n.º 5
0
async def test_cancel_twice(ladder_service: LadderService, player_factory):
    p1 = player_factory(login="******", player_id=1, ladder_rating=(1500, 500), ladder_games=0)
    p2 = player_factory(login="******", player_id=2, ladder_rating=(2000, 500), ladder_games=0)

    ladder_service.start_search([p1], "ladder1v1")
    search = ladder_service._searches[p1]["ladder1v1"]
    ladder_service.start_search([p2], "ladder1v1")
    search2 = ladder_service._searches[p2]["ladder1v1"]

    ladder_service.cancel_search(p1)
    assert search.is_cancelled
    assert not search2.is_cancelled

    ladder_service.cancel_search(p1)

    ladder_service.cancel_search(p2)
    assert search2.is_cancelled