test: US-08 DWN sync tests pass 50/50 — fix sync performance
- Make dwn.sync endpoint async: spawns background task, returns immediately - Add 90s overall timeout to sync_with_peers via tokio::time::timeout - Deduplicate peer onion addresses before syncing - Batch message pushes (50 per request) instead of one-at-a-time over Tor - Add 15s connect_timeout to Tor SOCKS5 client - Cap local message query to 200 messages per sync - Fix DWN HTTP handler to process ALL messages in batch (was only first) - Add recordId deduplication in handler to prevent duplicate imports - Update test script to poll dwn.status for sync completion Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -31,7 +31,18 @@ impl RpcHandler {
|
||||
}
|
||||
|
||||
/// Trigger DWN sync with connected peers.
|
||||
/// Spawns sync as a background task and returns immediately.
|
||||
pub(super) async fn handle_dwn_sync(&self) -> Result<serde_json::Value> {
|
||||
// Check if already syncing
|
||||
let current_state = dwn_sync::load_sync_state(&self.config.data_dir).await?;
|
||||
if matches!(current_state.status, dwn_sync::SyncStatus::Syncing) {
|
||||
return Ok(serde_json::json!({
|
||||
"sync_status": "syncing",
|
||||
"last_sync": current_state.last_sync,
|
||||
"messages_synced": current_state.messages_synced,
|
||||
}));
|
||||
}
|
||||
|
||||
let nodes = federation::load_nodes(&self.config.data_dir).await?;
|
||||
let onions: Vec<String> = nodes
|
||||
.iter()
|
||||
@@ -39,12 +50,19 @@ impl RpcHandler {
|
||||
.map(|n| n.onion.clone())
|
||||
.collect();
|
||||
|
||||
let state = dwn_sync::sync_with_peers(&self.config.data_dir, &onions).await?;
|
||||
// Spawn sync in background so we don't block the RPC response
|
||||
let data_dir = self.config.data_dir.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = dwn_sync::sync_with_peers(&data_dir, &onions).await {
|
||||
tracing::warn!(error = %e, "DWN background sync failed");
|
||||
}
|
||||
});
|
||||
|
||||
// Return immediately with "syncing" status
|
||||
Ok(serde_json::json!({
|
||||
"sync_status": state.status,
|
||||
"last_sync": state.last_sync,
|
||||
"messages_synced": state.messages_synced,
|
||||
"sync_status": "syncing",
|
||||
"last_sync": current_state.last_sync,
|
||||
"messages_synced": current_state.messages_synced,
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user