Skip to content

Commit e1d9876

Browse files
committed
graph: Speed up some tests by using shorter timeouts in debug builds
This also makes the timeouts used for IPFS requests configurable; the default of 1s in debug builds is too short for the runner tests in CI and we therefore set it to the 60s for release builds for those tests.
1 parent e449758 commit e1d9876

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ jobs:
7979
ports:
8080
- 5432:5432
8181
env:
82-
RUSTFLAGS: "-C link-arg=-fuse-ld=lld -D warnings"
82+
GRAPH_IPFS_REQUEST_TIMEOUT: "60"
83+
RUSTFLAGS: "-C link-arg=-fuse-ld=lld -D warnings --cfg test_with_ipfs"
8384
RUNNER_TESTS_WAIT_FOR_SYNC_SECS: "600"
8485
steps:
8586
- name: Tune GitHub hosted runner to reduce flakiness

graph/src/env/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ pub struct EnvVars {
248248
/// Set by the environment variable `GRAPH_FIREHOSE_BLOCK_BATCH_SIZE`.
249249
/// The default value is 10.
250250
pub firehose_block_batch_size: usize,
251+
/// Timeouts to use for various IPFS requests set by
252+
/// `GRAPH_IPFS_REQUEST_TIMEOUT`. Defaults to 60 seconds for release
253+
/// builds and one second for debug builds to speed up tests. The value
254+
/// is in seconds.
255+
pub ipfs_request_timeout: Duration,
251256
}
252257

253258
impl EnvVars {
@@ -256,6 +261,16 @@ impl EnvVars {
256261
let graphql = InnerGraphQl::init_from_env()?.into();
257262
let mapping_handlers = InnerMappingHandlers::init_from_env()?.into();
258263
let store = InnerStore::init_from_env()?.try_into()?;
264+
let ipfs_request_timeout = match inner.ipfs_request_timeout {
265+
Some(timeout) => Duration::from_secs(timeout),
266+
None => {
267+
if cfg!(debug_assertions) {
268+
Duration::from_secs(1)
269+
} else {
270+
Duration::from_secs(60)
271+
}
272+
}
273+
};
259274

260275
Ok(Self {
261276
graphql,
@@ -330,6 +345,7 @@ impl EnvVars {
330345
firehose_block_fetch_retry_limit: inner.firehose_block_fetch_retry_limit,
331346
firehose_block_fetch_timeout: inner.firehose_block_fetch_timeout,
332347
firehose_block_batch_size: inner.firehose_block_fetch_batch_size,
348+
ipfs_request_timeout,
333349
})
334350
}
335351

@@ -510,6 +526,8 @@ struct Inner {
510526
firehose_block_fetch_timeout: u64,
511527
#[envconfig(from = "GRAPH_FIREHOSE_FETCH_BLOCK_BATCH_SIZE", default = "10")]
512528
firehose_block_fetch_batch_size: usize,
529+
#[envconfig(from = "GRAPH_IPFS_REQUEST_TIMEOUT")]
530+
ipfs_request_timeout: Option<u64>,
513531
}
514532

515533
#[derive(Clone, Debug)]

graph/src/ipfs/gateway_client.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::sync::Arc;
2-
use std::time::Duration;
32

43
use anyhow::anyhow;
54
use async_trait::async_trait;
@@ -9,6 +8,7 @@ use http::header::CACHE_CONTROL;
98
use reqwest::StatusCode;
109
use slog::Logger;
1110

11+
use crate::env::ENV_VARS;
1212
use crate::ipfs::IpfsClient;
1313
use crate::ipfs::IpfsError;
1414
use crate::ipfs::IpfsRequest;
@@ -17,10 +17,6 @@ use crate::ipfs::IpfsResult;
1717
use crate::ipfs::RetryPolicy;
1818
use crate::ipfs::ServerAddress;
1919

20-
/// The request that verifies that the IPFS gateway is accessible is generally fast because
21-
/// it does not involve querying the distributed network.
22-
const TEST_REQUEST_TIMEOUT: Duration = Duration::from_secs(60);
23-
2420
/// A client that connects to an IPFS gateway.
2521
///
2622
/// Reference: <https://specs.ipfs.tech/http-gateways/path-gateway>
@@ -99,7 +95,7 @@ impl IpfsGatewayClient {
9995
}
10096
});
10197

102-
let ok = tokio::time::timeout(TEST_REQUEST_TIMEOUT, fut)
98+
let ok = tokio::time::timeout(ENV_VARS.ipfs_request_timeout, fut)
10399
.await
104100
.map_err(|_| anyhow!("request timed out"))??;
105101

@@ -151,6 +147,8 @@ impl IpfsClient for IpfsGatewayClient {
151147

152148
#[cfg(test)]
153149
mod tests {
150+
use std::time::Duration;
151+
154152
use bytes::BytesMut;
155153
use futures03::TryStreamExt;
156154
use wiremock::matchers as m;

graph/src/ipfs/retry_policy.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
use std::time::Duration;
2-
31
use slog::Logger;
42

53
use crate::ipfs::error::IpfsError;
64
use crate::prelude::*;
75
use crate::util::futures::retry;
86
use crate::util::futures::RetryConfig;
97

10-
/// The default maximum delay between retries.
11-
const DEFAULT_MAX_DELAY: Duration = Duration::from_secs(60);
12-
138
/// Describes retry behavior when IPFS requests fail.
149
#[derive(Clone, Copy, Debug)]
1510
pub enum RetryPolicy {
@@ -33,7 +28,7 @@ impl RetryPolicy {
3328
) -> RetryConfig<O, IpfsError> {
3429
retry(operation_name, logger)
3530
.limit(ENV_VARS.mappings.ipfs_max_attempts)
36-
.max_delay(DEFAULT_MAX_DELAY)
31+
.max_delay(ENV_VARS.ipfs_request_timeout)
3732
.when(move |result: &Result<O, IpfsError>| match result {
3833
Ok(_) => false,
3934
Err(err) => match self {

graph/src/ipfs/rpc_client.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use reqwest::Response;
99
use reqwest::StatusCode;
1010
use slog::Logger;
1111

12+
use crate::env::ENV_VARS;
1213
use crate::ipfs::IpfsClient;
1314
use crate::ipfs::IpfsError;
1415
use crate::ipfs::IpfsRequest;
@@ -17,10 +18,6 @@ use crate::ipfs::IpfsResult;
1718
use crate::ipfs::RetryPolicy;
1819
use crate::ipfs::ServerAddress;
1920

20-
/// The request that verifies that the IPFS RPC API is accessible is generally fast because
21-
/// it does not involve querying the distributed network.
22-
const TEST_REQUEST_TIMEOUT: Duration = Duration::from_secs(60);
23-
2421
/// A client that connects to an IPFS RPC API.
2522
///
2623
/// Reference: <https://docs.ipfs.tech/reference/kubo/rpc>
@@ -60,7 +57,7 @@ impl IpfsRpcClient {
6057
server_address: ServerAddress::new(server_address)?,
6158
http_client: reqwest::Client::new(),
6259
logger: logger.to_owned(),
63-
test_request_timeout: TEST_REQUEST_TIMEOUT,
60+
test_request_timeout: ENV_VARS.ipfs_request_timeout,
6461
})
6562
}
6663

@@ -88,7 +85,7 @@ impl IpfsRpcClient {
8885
}
8986
});
9087

91-
let ok = tokio::time::timeout(TEST_REQUEST_TIMEOUT, fut)
88+
let ok = tokio::time::timeout(ENV_VARS.ipfs_request_timeout, fut)
9289
.await
9390
.map_err(|_| anyhow!("request timed out"))??;
9491

0 commit comments

Comments
 (0)