forked from linkong/planet
release: bump version to 0.84.2
This commit is contained in:
1 parent
5e6352f524
commit
30b44ec00d
77 files changed
+3312
-1039
No files matched your search
@@ -434,3 +434,40 @@ async def test_cloud_apis_rbac_optimistic_lock_and_analytics(monkeypatch):
|
||||
assert r_clear.json()["meta"]["mode"] == "fallback_static"
|
||||
finally:
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
def test_resolve_effective_cloud_config_clamps_on_low_memory(monkeypatch):
|
||||
cfg = earth_clouds.CloudMapConfig(resolution="4096x2048")
|
||||
|
||||
monkeypatch.setattr(earth_clouds, "detect_container_memory_limit_mb", lambda: 500)
|
||||
clamped = earth_clouds.resolve_effective_cloud_config(cfg)
|
||||
assert clamped.resolution == "2048x1024"
|
||||
|
||||
monkeypatch.setattr(earth_clouds, "detect_container_memory_limit_mb", lambda: 2048)
|
||||
assert earth_clouds.resolve_effective_cloud_config(cfg).resolution == "4096x2048"
|
||||
|
||||
monkeypatch.setattr(earth_clouds, "detect_container_memory_limit_mb", lambda: None)
|
||||
assert earth_clouds.resolve_effective_cloud_config(cfg).resolution == "4096x2048"
|
||||
|
||||
|
||||
def test_fuse_and_synthesize_visual_layers_streams_png_payloads():
|
||||
from datetime import UTC, datetime
|
||||
from app.services.earth_clouds_fx import fuse_and_synthesize_visual_layers
|
||||
|
||||
ir_zero = np.zeros((32, 64), dtype=np.uint8)
|
||||
temp_grid = np.full((32, 64), 16.0, dtype=np.float32)
|
||||
temp_grid[9:13, 50:56] = 8.0
|
||||
vis_arr = np.zeros((32, 64, 4), dtype=np.uint8)
|
||||
vis_arr[:, :, 3] = 255
|
||||
vis_arr[9:13, 50:56, :3] = [215, 215, 215]
|
||||
|
||||
fused, webp = fuse_and_synthesize_visual_layers(
|
||||
ir_zero,
|
||||
temp_grid,
|
||||
[({"id": "himawari", "sub_lon": 140.7}, _make_png_bytes(vis_arr))],
|
||||
width=64,
|
||||
height=32,
|
||||
now_utc=datetime(2026, 12, 3, 5, 0, 0, tzinfo=UTC),
|
||||
)
|
||||
assert int(fused[11, 53]) >= 120
|
||||
assert webp is not None and len(webp) > 20
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import gc
|
||||
import io
|
||||
import weakref
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import httpx
|
||||
@@ -367,3 +370,101 @@ async def test_tile_proxy_gating_cache_lru_and_basemap_api(tmp_path, monkeypatch
|
||||
assert wind_tool["domain"] == "wind"
|
||||
finally:
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_or_fetch_tile_coalesces_concurrent_requests(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(earth_tiles, "TILES_DATA_DIR", tmp_path / "tiles")
|
||||
monkeypatch.setattr(
|
||||
earth_tiles,
|
||||
"_get_source_runtime_settings",
|
||||
AsyncMock(
|
||||
return_value=(
|
||||
True,
|
||||
earth_tiles.DEFAULT_TILE_TEMPLATES["earth_imagery_sentinel2"],
|
||||
{"max_zoom": 8, "request_timeout_seconds": 10},
|
||||
)
|
||||
),
|
||||
)
|
||||
calls = 0
|
||||
|
||||
async def slow_fetch(*_args, **_kwargs):
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
await asyncio.sleep(0.05)
|
||||
return b"RIFFcoalescedWEBP"
|
||||
|
||||
monkeypatch.setattr(earth_tiles, "_fetch_and_encode_tile", slow_fetch)
|
||||
results = await asyncio.gather(
|
||||
*(
|
||||
earth_tiles.get_or_fetch_tile("earth_imagery_sentinel2", 2, 1, 1)
|
||||
for _ in range(4)
|
||||
)
|
||||
)
|
||||
assert calls == 1
|
||||
assert results == [(b"RIFFcoalescedWEBP", True)] * 4
|
||||
|
||||
|
||||
def test_tile_encode_semaphore_limits_concurrency_without_retaining_closed_loop(monkeypatch):
|
||||
monkeypatch.setenv("PLANET_TILE_ENCODE_CONCURRENCY", "1")
|
||||
|
||||
async def contend_for_semaphore():
|
||||
waiting = asyncio.Event()
|
||||
entered = asyncio.Event()
|
||||
|
||||
async def acquire():
|
||||
waiting.set()
|
||||
async with earth_tiles._get_tile_encode_semaphore():
|
||||
entered.set()
|
||||
|
||||
async with earth_tiles._get_tile_encode_semaphore():
|
||||
contender = asyncio.create_task(acquire())
|
||||
await waiting.wait()
|
||||
assert not entered.is_set()
|
||||
|
||||
await contender
|
||||
assert entered.is_set()
|
||||
return weakref.ref(asyncio.get_running_loop())
|
||||
|
||||
loop_ref = asyncio.run(contend_for_semaphore())
|
||||
gc.collect()
|
||||
assert loop_ref() is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cleanup_stale_running_tasks_include_all_running(monkeypatch):
|
||||
from datetime import UTC, datetime
|
||||
from types import SimpleNamespace
|
||||
from contextlib import asynccontextmanager
|
||||
from app.services import scheduler
|
||||
|
||||
fresh_task = SimpleNamespace(
|
||||
id=111,
|
||||
status="running",
|
||||
phase="fetching",
|
||||
started_at=datetime.now(UTC),
|
||||
completed_at=None,
|
||||
error_message="",
|
||||
)
|
||||
committed = False
|
||||
|
||||
class _FakeDb:
|
||||
async def execute(self, _stmt):
|
||||
return SimpleNamespace(scalars=lambda: SimpleNamespace(all=lambda: [fresh_task]))
|
||||
|
||||
async def commit(self):
|
||||
nonlocal committed
|
||||
committed = True
|
||||
|
||||
@asynccontextmanager
|
||||
async def _fake_session_factory():
|
||||
yield _FakeDb()
|
||||
|
||||
monkeypatch.setattr(scheduler, "async_session_factory", _fake_session_factory)
|
||||
cleaned = await scheduler.cleanup_stale_running_tasks(include_all_running=True)
|
||||
assert cleaned == 1
|
||||
assert committed is True
|
||||
assert fresh_task.status == "failed"
|
||||
assert fresh_task.phase == "failed"
|
||||
assert fresh_task.completed_at is not None
|
||||
assert "backend restart" in fresh_task.error_message
|
||||
Reference in new issue
Block a user