Skip to content

Commit bbf70d4

Browse files
committed
test: harden ping manual partial-connectivity scenario
1 parent 0e8a681 commit bbf70d4

File tree

6 files changed

+60
-18
lines changed

6 files changed

+60
-18
lines changed

apps/freenet-ping/Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/freenet-ping/app/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[features]
77
testing = ["freenet-stdlib/testing", "freenet/testing"]
8+
manual-tests = []
89

910
[dependencies]
1011
anyhow = "1.0"

apps/freenet-ping/app/src/ping_client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub async fn wait_for_put_response(
4747
expected_key: &ContractKey,
4848
) -> Result<ContractKey, Box<dyn std::error::Error + Send + Sync + 'static>> {
4949
loop {
50-
let resp = timeout(Duration::from_secs(30), client.recv()).await;
50+
let resp = timeout(Duration::from_secs(60), client.recv()).await;
5151
match resp {
5252
Ok(Ok(HostResponse::ContractResponse(ContractResponse::PutResponse { key }))) => {
5353
if &key == expected_key {
@@ -91,7 +91,7 @@ pub async fn wait_for_get_response(
9191
expected_key: &ContractKey,
9292
) -> Result<Ping, Box<dyn std::error::Error + Send + Sync + 'static>> {
9393
loop {
94-
let resp = timeout(Duration::from_secs(30), client.recv()).await;
94+
let resp = timeout(Duration::from_secs(60), client.recv()).await;
9595
match resp {
9696
Ok(Ok(HostResponse::ContractResponse(ContractResponse::GetResponse {
9797
key,
@@ -134,7 +134,7 @@ pub async fn wait_for_subscribe_response(
134134
expected_key: &ContractKey,
135135
) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
136136
loop {
137-
let resp = timeout(Duration::from_secs(30), client.recv()).await;
137+
let resp = timeout(Duration::from_secs(60), client.recv()).await;
138138
match resp {
139139
Ok(Ok(HostResponse::ContractResponse(ContractResponse::SubscribeResponse {
140140
key,

apps/freenet-ping/app/tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ Run a specific blocked peers test variant:
8888
cargo test test_ping_blocked_peers_simple
8989
```
9090

91-
Run the large-scale partial connectivity network test:
91+
Run the large-scale partial connectivity network test (requires the manual test feature because the scenario is still experimental):
9292

9393
```bash
94-
cargo test -p freenet-ping-app --test run_app_partially_connected_network
94+
cargo test -p freenet-ping-app --features manual-tests --test run_app test_ping_partially_connected_network
9595
```
9696

9797
---

apps/freenet-ping/app/tests/common/mod.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,23 @@ pub(crate) enum PackageType {
208208
Delegate,
209209
}
210210

211+
const CONTRACT_EXTRA_FEATURES: [&str; 1] = ["contract"];
212+
const NO_EXTRA_FEATURES: [&str; 0] = [];
213+
211214
impl PackageType {
212215
pub fn feature(&self) -> &'static str {
213216
match self {
214217
PackageType::Contract => "freenet-main-contract",
215218
PackageType::Delegate => "freenet-main-delegate",
216219
}
217220
}
221+
222+
pub fn extra_features(&self) -> &'static [&'static str] {
223+
match self {
224+
PackageType::Contract => &CONTRACT_EXTRA_FEATURES,
225+
PackageType::Delegate => &NO_EXTRA_FEATURES,
226+
}
227+
}
218228
}
219229

220230
impl std::fmt::Display for PackageType {
@@ -250,9 +260,10 @@ fn compile_options(cli_config: &BuildToolConfig) -> impl Iterator<Item = String>
250260
.iter()
251261
.flat_map(|s| {
252262
s.split(',')
253-
.filter(|p| *p != cli_config.package_type.feature())
263+
.filter(|p| *p != cli_config.package_type.feature() && *p != "contract")
254264
})
255-
.chain([cli_config.package_type.feature()]);
265+
.chain([cli_config.package_type.feature()])
266+
.chain(cli_config.package_type.extra_features().iter().copied());
256267
let features = [
257268
"--features".to_string(),
258269
feature_list.collect::<Vec<_>>().join(","),
@@ -262,7 +273,33 @@ fn compile_options(cli_config: &BuildToolConfig) -> impl Iterator<Item = String>
262273
.chain(release.iter().map(|s| s.to_string()))
263274
}
264275
// TODO: refactor so we share the implementation with fdev (need to extract to )
276+
fn ensure_target_dir_env() {
277+
if std::env::var(TARGET_DIR_VAR).is_err() {
278+
let workspace_dir = std::env::var("CARGO_WORKSPACE_DIR")
279+
.map(PathBuf::from)
280+
.unwrap_or_else(|_| find_workspace_root());
281+
let target_dir = workspace_dir.join("target");
282+
std::env::set_var(TARGET_DIR_VAR, &target_dir);
283+
}
284+
}
285+
286+
fn find_workspace_root() -> PathBuf {
287+
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
288+
manifest_dir
289+
.ancestors()
290+
.find(|dir| {
291+
let cargo_toml = dir.join("Cargo.toml");
292+
cargo_toml.exists()
293+
&& std::fs::read_to_string(&cargo_toml)
294+
.map(|contents| contents.contains("[workspace]"))
295+
.unwrap_or(false)
296+
})
297+
.expect("Could not determine workspace root from manifest directory")
298+
.to_path_buf()
299+
}
300+
265301
fn compile_contract(contract_path: &PathBuf) -> anyhow::Result<Vec<u8>> {
302+
ensure_target_dir_env();
266303
println!("module path: {contract_path:?}");
267304
let target = std::env::var(TARGET_DIR_VAR)
268305
.map_err(|_| anyhow::anyhow!("CARGO_TARGET_DIR should be set"))?;

apps/freenet-ping/app/tests/run_app.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,8 +1519,8 @@ async fn test_ping_application_loop() -> TestResult {
15191519
Ok(())
15201520
}
15211521

1522+
#[cfg(feature = "manual-tests")]
15221523
#[tokio::test(flavor = "multi_thread")]
1523-
#[ignore = "Test has never worked - gateway nodes fail on startup with channel closed errors"]
15241524
async fn test_ping_partially_connected_network() -> TestResult {
15251525
/*
15261526
* This test verifies how subscription propagation works in a partially connected network.
@@ -1750,15 +1750,18 @@ async fn test_ping_partially_connected_network() -> TestResult {
17501750
i, NUM_GATEWAYS, num_connections);
17511751
}
17521752

1753-
// Load the ping contract
1753+
// Load the ping contract. Compile once to determine the code hash, then again with proper options.
17541754
let path_to_code = PathBuf::from(PACKAGE_DIR).join(PATH_TO_CONTRACT);
17551755
tracing::info!(path=%path_to_code.display(), "loading contract code");
1756-
let code = std::fs::read(path_to_code)
1757-
.ok()
1758-
.ok_or_else(|| anyhow!("Failed to read contract code"))?;
1759-
let code_hash = CodeHash::from_code(&code);
1760-
1761-
// Create ping contract options
1756+
let temp_options = PingContractOptions {
1757+
frequency: Duration::from_secs(3),
1758+
ttl: Duration::from_secs(60),
1759+
tag: APP_TAG.to_string(),
1760+
code_key: String::new(),
1761+
};
1762+
let temp_params = Parameters::from(serde_json::to_vec(&temp_options).unwrap());
1763+
let temp_container = common::load_contract(&path_to_code, temp_params)?;
1764+
let code_hash = CodeHash::from_code(temp_container.data());
17621765
let ping_options = PingContractOptions {
17631766
frequency: Duration::from_secs(3),
17641767
ttl: Duration::from_secs(60),
@@ -1767,7 +1770,7 @@ async fn test_ping_partially_connected_network() -> TestResult {
17671770
};
17681771

17691772
let params = Parameters::from(serde_json::to_vec(&ping_options).unwrap());
1770-
let container = ContractContainer::try_from((code, &params))?;
1773+
let container = common::load_contract(&path_to_code, params)?;
17711774
let contract_key = container.key();
17721775

17731776
// Choose a node to publish the contract

0 commit comments

Comments
 (0)