fix: refresh relays and provider id from other workers before sharing stats

This commit is contained in:
Ashen
2026-10-01 14:40:29 +05:30
parent e8a6ea93cb
commit ac6d5ab003
2 changed files with 33 additions and 4 deletions
+3 -1
View File
@@ -34,7 +34,9 @@ async def _read_state() -> DeliveryStateSnapshot:
# Read the fence before the setting so a later opt-out refuses activation. # Read the fence before the setting so a later opt-out refuses activation.
state = await get_analytics_v2_delivery_state(create_session) state = await get_analytics_v2_delivery_state(create_session)
async with create_session() as session: async with create_session() as session:
await SettingsService.refresh(session, ("enable_analytics_sharing",)) await SettingsService.refresh(
session, ("enable_analytics_sharing", "relays", "provider_id")
)
secret = await session.get(Secret, 1) secret = await session.get(Secret, 1)
if secret is not None and secret.nsec_state != NsecState.legacy: if secret is not None and secret.nsec_state != NsecState.legacy:
if secret.nsec_state == NsecState.encrypted: if secret.nsec_state == NsecState.encrypted:
+30 -3
View File
@@ -136,6 +136,35 @@ async def test_opt_out_saved_by_another_worker_is_not_undone(
).sharing_enabled ).sharing_enabled
@pytest.mark.asyncio
async def test_relays_saved_by_another_worker_move_publication(
node: Any, monkeypatch: Any
) -> None:
monkeypatch.setattr(runtime.settings, "enable_analytics_sharing", True)
await node.coordinator.prepare_startup()
await node.coordinator.sync_once()
assert node.coordinator._relays == ("wss://relay.example.com",)
# Another worker saved new relays; this one still holds the old list.
async with node.sessions() as session:
await session.exec( # type: ignore[call-overload]
text("INSERT INTO settings (id, data) VALUES (1, :data)").bindparams(
data=json.dumps(
{
"enable_analytics_sharing": True,
"relays": ["wss://relay.example.org"],
}
)
)
)
await session.commit()
await node.coordinator.sync_once()
await asyncio.sleep(0)
assert node.coordinator._relays == ("wss://relay.example.org",)
assert node.events == ["start:daily", "stop:daily", "start:daily"]
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_missing_identity_does_not_stop_private_collection( async def test_missing_identity_does_not_stop_private_collection(
node: Any, monkeypatch: Any node: Any, monkeypatch: Any
@@ -338,9 +367,7 @@ async def test_upgrade_preserves_existing_sharing_choice_across_restart(
) )
) )
).one() ).one()
assert epoch.coverage_start_day == datetime.now(UTC).date() + timedelta( assert epoch.coverage_start_day == datetime.now(UTC).date() + timedelta(days=1)
days=1
)
await node.coordinator.close() await node.coordinator.close()
async with node.sessions() as session: async with node.sessions() as session: