Skip to content

Commit 3f3a942

Browse files
Merge #77
77: feat(func-tests): re-use uploaded programs r=andreasbros a=andreasbros ## Motivation Every time you run functional tests, they start with uploading programs (20 of them) which can take couple minutes in mainnet. This change allows to re-use previously uploaded programs, saving time and money (NIL), especially when you only want to run a single test against remote network from your local machine. ## Solution - Dump uploaded programs IDs JSON in log output, which then when needed can be copied into a file locally - Provide uploaded programs IDs file as env var when running tests Note: this is only to be used when running tests from local dev environment * [ ] [CONTRIBUTING](https://github.com/NillionNetwork/nillion/blob/main/CONTRIBUTING.md) guidelines followed * [ ] Unit tests added/updated (if applicable) * [ ] Breaking change analysis completed (if applicable). "Will this change require all network cluster operators to update? Does it break public APIs? * [ ] For new features or breaking changes, created a documentation issue in [nillion-docs](https://github.com/NillionNetwork/nillion-docs/issues/new/choose) Co-authored-by: Andreas Abros <[email protected]>
2 parents 2424d3a + c1a29e3 commit 3f3a942

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/fixtures/nodes/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tempfile = "3.10.1"
1515
tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] }
1616
xshell = "0.2"
1717
serde_yaml = "0.9"
18+
serde_json = "1.0"
1819
tracing = "0.1"
1920

2021
basic-types = { path = "../../../libs/basic-types" }

tests/fixtures/nodes/src/nodes.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ extern "C" fn cleanup_at_exit() {
6565
}
6666

6767
/// The set of pre-uploaded test programs.
68+
#[derive(Serialize, Deserialize, Debug)]
6869
pub struct UploadedPrograms(pub(crate) HashMap<String, String>);
6970

7071
impl UploadedPrograms {
@@ -508,17 +509,25 @@ pub fn nodes(_tracing: &Tracing) -> Nodes {
508509
nodes.uploaded_programs = thread::scope(|s| {
509510
let namespace = s
510511
.spawn(|| {
511-
PAYMENTS_RUNTIME
512-
.block_on(async {
513-
nodes.wait_network_ready().await.expect("network did not become ready in time");
514-
upload_programs(&nodes).await
515-
})
516-
.expect("uploading programs failed")
512+
PAYMENTS_RUNTIME.block_on(async {
513+
// nodes fixture needs to wait for the network to be ready to discover the bootnode, regardless of the programs being uploaded
514+
nodes.wait_network_ready().await.expect("network did not become ready in time");
515+
516+
if let Ok(file_path) = env::var("UPLOADED_PROGRAMS_ID_FILE") {
517+
let json_data = fs::read_to_string(&file_path)
518+
.unwrap_or_else(|_| panic!("failed to read uploaded programs file: {}", file_path));
519+
serde_json::from_str(&json_data)
520+
.unwrap_or_else(|_| panic!("failed to parse uploaded programs JSON in file: {}", file_path))
521+
} else {
522+
upload_programs(&nodes).await.expect("uploading programs failed")
523+
}
524+
})
517525
})
518526
.join()
519527
.expect("program upload thread failed");
520528
namespace
521529
});
530+
522531
nodes
523532
}
524533

tests/fixtures/nodes/src/programs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ pub(crate) async fn upload_programs(nodes: &Nodes) -> anyhow::Result<UploadedPro
3535
info!("Uploaded {} programs in {:?}", PROGRAMS.metadata.len(), elapsed);
3636

3737
let namespace = UploadedPrograms(ids);
38+
39+
info!("Uploaded programs JSON:\n{}", serde_json::to_string(&namespace)?);
40+
3841
Ok(namespace)
3942
}

0 commit comments

Comments
 (0)