umap/umap/tests/test_websocket_server.py
Alexis Métaireau 5485fb99ab feat(sync): Send remote operations to peers when they join.
- Operations are now stored locally in memory. All operations are tied
  to an HLC (Hybrid Logical Clock), making it possible to order them
  concistently.

- Messages are handled in their `on*` methods, leading to a clearer
  implementation.

- When a new peer joins, it asks a random peer for the list of
  operations, and re-apply them locally.

- Messages types names have been updated to follow CamelCase, and to be
  similar across the client and the server.

- Pass `sync=False` to `makeFeature` in the updaters, to avoid
  generating duplicate operations on message retrieval.
2024-09-27 18:26:47 +02:00

22 lines
696 B
Python

from umap.websocket_server import OperationMessage, PeerMessage, Request, ServerRequest
def test_messages_are_parsed_correctly():
server = Request.model_validate(dict(kind="Server", action="list-peers")).root
assert type(server) is ServerRequest
operation = Request.model_validate(
dict(
kind="OperationMessage",
verb="upsert",
subject="map",
metadata={},
key="key",
)
).root
assert type(operation) is OperationMessage
peer_message = Request.model_validate(
dict(kind="PeerMessage", sender="Alice", recipient="Bob", message={})
).root
assert type(peer_message) is PeerMessage