Beispiel #1
0
async def test_cleanup_empty_room(room_store: RoomStore) -> None:
    """Verify that rooms with no actions do no break clear_load_test_rooms"""
    await room_store.add_request('empty-room-id', Request('request-id', []))
    await room_store.add_request('load-room-id', LOAD_TEST_REQUEST)

    await clear_load_test_rooms(room_store)
    assert await room_store.room_exists('load-room-id') is False
Beispiel #2
0
async def test_room_data_is_stored(room_store: RoomStore,
                                   rate_limiter: RateLimiter) -> None:
    gss_one = GameStateServer(room_store, rate_limiter, NoopRateLimiter())
    responses = await collect_responses(
        gss_one,
        requests=[
            Request(
                request_id='first-request-id',
                actions=[VALID_ACTION, ANOTHER_VALID_ACTION],
            )
        ],
        response_count=2,
    )

    assert responses == [
        ConnectionResponse([]),
        UpdateResponse([VALID_ACTION, ANOTHER_VALID_ACTION],
                       'first-request-id'),
    ]

    gss_two = GameStateServer(room_store, rate_limiter, NoopRateLimiter())
    responses = await collect_responses(gss_two, requests=[], response_count=1)
    assert responses == [
        ConnectionResponse([VALID_TOKEN, ANOTHER_VALID_TOKEN])
    ]
Beispiel #3
0
    def add_token(self) -> None:
        start_x = random.randint(0, 400)
        start_y = random.randint(0, 400)
        start_z = random.randint(0, 400)
        token_id = str(uuid.uuid4())

        self.client.send(
            Request(
                str(uuid.uuid4()),
                actions=[
                    UpsertAction(
                        Token(
                            id=token_id,
                            type='character',
                            contents=IconTokenContents(LOAD_TEST_ICON_ID),
                            start_x=start_x,
                            start_y=start_y,
                            start_z=start_z,
                            end_x=start_x + 1,
                            end_y=start_y + 1,
                            end_z=start_z + 1,
                        ), )
                ],
            ))

        self.tokens_ids_sent.append(token_id)
Beispiel #4
0
 def ping(self) -> None:
     self.client.send(
         Request(
             str(uuid.uuid4()),
             actions=[
                 PingAction(Ping(str(uuid.uuid4()), type='ping', x=1, y=1))
             ],
         ))
Beispiel #5
0
 def on_stop(self) -> None:
     # Delete all the tokens from the room to avoid saving load test rooms
     # to the store
     actions: List[Action] = [
         DeleteAction(token_id) for token_id in self.tokens_ids_sent
     ]
     self.client.send(Request(request_id=str(uuid.uuid4()),
                              actions=actions))
Beispiel #6
0
async def test_ping(gss: GameStateServer) -> None:
    responses = await collect_responses(
        gss,
        requests=[Request('ping-request-id', [PING_ACTION])],
        response_count=2,
    )
    assert responses == [
        ConnectionResponse([]),
        UpdateResponse([PING_ACTION], 'ping-request-id'),
    ]
Beispiel #7
0
async def test_add_duplicate_color(gss: GameStateServer) -> None:
    responses = await collect_responses(
        gss,
        requests=[
            Request(
                'same-color-request-id',
                [VALID_ACTION, VALID_ACTION_WITH_DUPLICATE_COLOR],
            )
        ],
        response_count=2,
    )
    assert responses == [
        ConnectionResponse([]),
        UpdateResponse([VALID_ACTION, VALID_ACTION_WITH_DUPLICATE_COLOR],
                       'same-color-request-id'),
    ]
Beispiel #8
0
async def test_multiple_pings(gss: GameStateServer) -> None:
    ping1 = PingAction(Ping('ping-id-1', 'ping', 0, 0))
    ping2 = PingAction(Ping('ping-id-2', 'ping', 0, 0))
    ping3 = PingAction(Ping('ping-id-3', 'ping', 0, 0))
    responses = await collect_responses(
        gss,
        requests=[Request(
            'ping-request-id',
            [ping1, ping2, ping3],
        )],
        response_count=2,
    )
    assert responses == [
        ConnectionResponse([]),
        UpdateResponse([ping1, ping2, ping3], 'ping-request-id'),
    ]
Beispiel #9
0
async def _requests(client: WebsocketClient) -> AsyncIterator[Request]:
    async for raw_message in client.requests():
        try:
            message = json.loads(raw_message)
            request = dacite.from_dict(Request, message)
        except (json.JSONDecodeError, WrongTypeError, MissingValueError):
            logger.info(
                'invalid json received from client',
                extra={'json': raw_message},
                exc_info=True,
            )
            raise InvalidRequestException()

        yield Request(
            actions=request.actions,
            request_id=request.request_id,
        )
Beispiel #10
0
async def test_color_persistence(compactor: Compactor, room_store: RoomStore) -> None:
    green_token = Token(
        id='new_token_id',
        type='character',
        contents=VALID_TOKEN.contents,
        start_x=2,
        start_y=2,
        start_z=2,
        end_x=3,
        end_y=3,
        end_z=3,
        color_rgb=colors[1],
    )
    await room_store.add_request(TEST_ROOM_ID, VALID_REQUEST)
    await room_store.add_request(
        TEST_ROOM_ID, Request('new_request', [UpsertAction(green_token)])
    )
    await room_store.add_request(TEST_ROOM_ID, DELETE_REQUEST)
    await room_store.acquire_replacement_lock(TEST_COMPACTOR_ID)
    await compactor._compact_room(TEST_ROOM_ID)
    assert await room_store.read(TEST_ROOM_ID) == [UpsertAction(green_token)]
Beispiel #11
0
async def test_mutate_and_read(room_store: RoomStore) -> None:
    updates: List[Action] = [VALID_ACTION, PING_ACTION]
    await room_store.add_request(TEST_ROOM_ID, Request(TEST_REQUEST_ID,
                                                       updates))
    assert list(await room_store.read(TEST_ROOM_ID)) == [VALID_ACTION]
Beispiel #12
0
import pytest

from load.clear_load_test_rooms import clear_load_test_rooms
from load.constants import LOAD_TEST_ICON_ID
from src.api.api_structures import Request, UpsertAction
from src.game_components import IconTokenContents
from src.room_store.memory_room_store import MemoryRoomStore, MemoryRoomStorage
from src.room_store.room_store import RoomStore
from tests.static_fixtures import VALID_REQUEST, VALID_TOKEN

pytestmark = pytest.mark.asyncio

LOAD_TEST_REQUEST = Request(
    'request-id',
    actions=[
        UpsertAction(
            dataclasses.replace(VALID_TOKEN,
                                contents=IconTokenContents(LOAD_TEST_ICON_ID)))
    ],
)


@pytest.fixture
def room_store() -> RoomStore:
    return MemoryRoomStore(MemoryRoomStorage())


async def test_cleanup(room_store: RoomStore) -> None:
    await room_store.add_request('regular-room-id', VALID_REQUEST)
    await room_store.add_request('load-room-id', LOAD_TEST_REQUEST)

    await clear_load_test_rooms(room_store)
Beispiel #13
0
    IconTokenContents('another_icon_id'),
    start_x=1,
    start_y=1,
    start_z=1,
    end_x=2,
    end_y=2,
    end_z=2,
    color_rgb=colors[1],
)
VALID_PING = Ping('ping_id', 'ping', 0, 0)
UPDATED_TOKEN = Token(
    VALID_TOKEN.id,
    VALID_TOKEN.type,
    VALID_TOKEN.contents,
    7,
    8,
    9,
    8,
    9,
    10,
    colors[0],
)
VALID_ACTION = UpsertAction(data=VALID_TOKEN)
VALID_ACTION_WITH_DUPLICATE_COLOR = UpsertAction(data=VALID_TOKEN_WITH_DUPLICATE_COLOR)
DELETE_VALID_TOKEN = DeleteAction(data=VALID_TOKEN.id)
ANOTHER_VALID_ACTION = UpsertAction(data=ANOTHER_VALID_TOKEN)
PING_ACTION = PingAction(data=VALID_PING)
VALID_REQUEST = Request('request_id', [VALID_ACTION])
VALID_MOVE_REQUEST = Request('move_request_id', [UpsertAction(data=UPDATED_TOKEN)])
DELETE_REQUEST = Request('delete-request-id', [DELETE_VALID_TOKEN])