step 6: add stable overlays and live update stress tests
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from threading import Thread
|
||||
|
||||
import pytest
|
||||
|
||||
import dpg_map as dpgm
|
||||
from dpg_map.commands import CommandKind
|
||||
from dpg_map.exceptions import CoordinateError
|
||||
from dpg_map.overlays import TrajectoryOverlay
|
||||
from dpg_map.state import DirtyFlags, create_map_state, get_map_state
|
||||
@@ -61,3 +64,39 @@ def test_layer_state_tracks_visibility_and_overlay_membership() -> None:
|
||||
|
||||
assert state.layers["fleet"].overlay_tags == set()
|
||||
assert "vehicle" not in state.overlays
|
||||
|
||||
|
||||
def test_threaded_marker_updates_coalesce_without_touching_view_or_drag_state() -> None:
|
||||
create_map_state(tag="threaded-marker", center=(47.0, 2.0), zoom=9)
|
||||
dpgm.add_marker("vehicle", lat=47.0, lon=2.0, map_tag="threaded-marker")
|
||||
state = get_map_state("threaded-marker")
|
||||
state.command_queue.drain()
|
||||
state.dirty = DirtyFlags.NONE
|
||||
state.interaction.active_drag = True
|
||||
state.interaction.last_mouse_position = (100.0, 100.0)
|
||||
before_center = state.center
|
||||
before_zoom = state.zoom
|
||||
|
||||
def update_worker(offset: float) -> None:
|
||||
for index in range(100):
|
||||
dpgm.update_marker(
|
||||
"vehicle",
|
||||
lat=47.0 + offset,
|
||||
lon=2.0 + index * 0.00001,
|
||||
map_tag="threaded-marker",
|
||||
)
|
||||
|
||||
threads = [Thread(target=update_worker, args=(worker * 0.0001,)) for worker in range(4)]
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
|
||||
commands = state.command_queue.drain()
|
||||
|
||||
assert state.center == before_center
|
||||
assert state.zoom == before_zoom
|
||||
assert state.interaction.active_drag is True
|
||||
assert state.interaction.last_mouse_position == (100.0, 100.0)
|
||||
assert state.dirty == DirtyFlags.OVERLAYS
|
||||
assert [command.kind for command in commands] == [CommandKind.UPDATE_OVERLAY]
|
||||
|
||||
Reference in New Issue
Block a user