Skip to content

Commit

Permalink
ergo-rest: increase timeout + reduce maximum number of connections in…
Browse files Browse the repository at this point in the history
… tests
  • Loading branch information
SethDusek committed May 1, 2024
1 parent 4595115 commit f510264
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions bindings/ergo-lib-wasm/tests_browser/test_rest_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ it('node REST API: peer_discovery endpoint', async () => {
// there's an unavoidable waiting time of 80 seconds, to give Chrome time to relinquish failed
// preflight requests)
let is_chrome = true;
let active_peers = await ergo_wasm.peer_discovery(seeds, 150, 140, is_chrome);
let active_peers = await ergo_wasm.peer_discovery(seeds, 20, 200, is_chrome);
assert(active_peers.len() > 0);
console.log("Number active peers:", active_peers.len(), ". First active peer: ", active_peers.get(0).href);
});
Expand All @@ -25,10 +25,10 @@ it('node REST API: peer_discovery endpoint (INCREMENTAL VERSION)', async () => {
const seeds = get_ergo_node_seeds();
let scan = new ergo_wasm.ChromePeerDiscoveryScan(seeds);

scan = await ergo_wasm.incremental_peer_discovery_chrome(scan, 150, 90);
scan = await ergo_wasm.incremental_peer_discovery_chrome(scan, 20, 200);
let scan_1_len = scan.active_peers().len();
console.log("# active peers from first scan:", scan_1_len);
scan = await ergo_wasm.incremental_peer_discovery_chrome(scan, 150, 480);
scan = await ergo_wasm.incremental_peer_discovery_chrome(scan, 20, 480);
let scan_2_len = scan.active_peers().len();
console.log("# active peers from second scan:", scan_2_len);

Expand Down
31 changes: 16 additions & 15 deletions ergo-rest/src/api/peer_discovery_internals/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ pub(crate) async fn peer_discovery_inner_chrome(
max_parallel_tasks: BoundedU16<1, { u16::MAX }>,
timeout: Duration,
) -> Result<ChromePeerDiscoveryScan, PeerDiscoveryError> {
if timeout.as_secs() < 90 {
if timeout.as_secs() < 180 {
return Err(PeerDiscoveryError::TimeoutTooShort);
}

// Note that 80 seconds is allocated to waiting for preflight requests to naturally timeout by
// Chrome. The remaining time is spent looking for peers.
let global_timeout = timeout.checked_sub(Duration::from_secs(80)).unwrap();
let global_timeout = timeout.checked_sub(Duration::from_secs(180)).unwrap();
let settings = PeerDiscoverySettings {
max_parallel_tasks,
task_2_buffer_length: 50,
Expand Down Expand Up @@ -340,10 +340,11 @@ async fn peer_discovery_impl_chrome(
while let Some(req) = pending_requests.pop() {
pending_requests_after_timeout.push(req);
}
//console_log!(
// "GLOBAL TIMEOUT, {} incomplete requests-------------------------",
// pending_requests_after_timeout.len()
//);
// console_log!(
// "GLOBAL TIMEOUT, {} incomplete requests-------------------------",
// pending_requests_after_timeout.len()
// );
break;
}
}
}
Expand All @@ -355,15 +356,15 @@ async fn peer_discovery_impl_chrome(
.cloned()
.collect();
// Uncomment for debugging
//console_log!("Active_peers: {:?}", active_peers);
//console_log!(
// "Total # nodes visited: {}, # peers found: {}, # incomplete requests: {}",
// visited_peers.len(),
// active_peers.len(),
// pending_requests_after_timeout.len(),
//);
//console_log!("Waiting 80sec for Chrome to relinquish pending HTTP requests");
crate::wasm_timer::Delay::new(Duration::from_secs(80)).await?;
// console_log!("Active_peers: {:?}", active_peers);
// console_log!(
// "Total # nodes visited: {}, # peers found: {}, # incomplete requests: {}",
// visited_peers.len(),
// active_peers.len(),
// pending_requests_after_timeout.len(),
// );
//console_log!("Waiting 180sec for Chrome to relinquish pending HTTP requests");
crate::wasm_timer::Delay::new(Duration::from_secs(180)).await?;
Ok(ChromePeerDiscoveryScan {
active_peers,
visited_peers,
Expand Down

0 comments on commit f510264

Please sign in to comment.