Skip to content

Commit

Permalink
run-tests: allow building of dependencies; update test templates
Browse files Browse the repository at this point in the history
  • Loading branch information
nick1udwig committed Jul 12, 2024
1 parent 2e446cc commit 9c0e28a
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 169 deletions.
1 change: 1 addition & 0 deletions src/new/templates/test/chat/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ runtime_build_release = false


[[tests]]
dependency_package_paths = [".."]
setup_packages = [
{ path = "..", run = true }
]
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
"code_hashes": {
"0.1.0": ""
},
"wit_version": 0
"wit_version": 0,
"dependencies": [
"{package_name}:{publisher}",
"tester:sys"
]
},
"external_url": "",
"animation_url": ""
Expand Down
1 change: 1 addition & 0 deletions src/new/templates/test/echo/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ runtime_build_release = false


[[tests]]
dependency_package_paths = []
setup_packages = [
{ path = "..", run = true }
]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
world {package_name_kebab}-test-{publisher_dotted_kebab}-v0 {
import tester;
include process-v0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
"code_hashes": {
"0.1.0": ""
},
"wit_version": 0
"wit_version": 0,
"dependencies": [
"tester:sys"
]
},
"external_url": "",
"animation_url": ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod tester_lib;

wit_bindgen::generate!({
path: "target/wit",
world: "tester-sys-v0",
world: "{package_name_kebab}-test-{publisher_dotted_kebab}-v0",
generate_unused_types: true,
additional_derives: [PartialEq, serde::Deserialize, serde::Serialize, process_macros::SerdeJsonInto],
});
Expand Down
1 change: 1 addition & 0 deletions src/new/templates/test/fibonacci/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ runtime_build_release = false


[[tests]]
dependency_package_paths = [".."]
setup_packages = [
{ path = "..", run = true }
]
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
"code_hashes": {
"0.1.0": ""
},
"wit_version": 0
"wit_version": 0,
"dependencies": [
"{package_name}:{publisher}",
"tester:sys"
]
},
"external_url": "",
"animation_url": ""
Expand Down
164 changes: 123 additions & 41 deletions src/run_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,122 @@ async fn boot_nodes(
Ok(())
}

#[instrument(level = "trace", skip_all)]
async fn build_packages(
test: &Test,
test_dir_path: &Path,
detached: &bool,
persist_home: &bool,
runtime_path: &Path,
) -> Result<(Vec<SetupPackage>, Vec<PathBuf>)> {
let setup_packages: Vec<SetupPackage> = test
.setup_packages
.iter()
.cloned()
.map(|s| {
SetupPackage {
path: test_dir_path.join(s.path).canonicalize().unwrap(),
run: s.run,
}
})
.collect();
let test_package_paths: Vec<PathBuf> = test
.test_package_paths
.iter()
.cloned()
.map(|p| test_dir_path.join(p).canonicalize().unwrap())
.collect();

info!("Starting node to host dependencies...");
let port = test.nodes[0].port.clone();
let home = PathBuf::from("/tmp/kinode-fake-node");
let nodes = vec![Node {
port: port.clone(),
home,
fake_node_name: "fake.dev".into(),
password: None,
rpc: None,
runtime_verbosity: Some(2),
}];

let SetupCleanupReturn {
send_to_cleanup,
send_to_kill,
task_handles: _,
cleanup_context: _cleanup_context,
mut master_node_port,
node_cleanup_infos,
node_handles,
} = setup_cleanup(detached, persist_home).await?;

// boot fakechain
let recv_kill_in_start_chain = send_to_kill.subscribe();
let anvil_process =
chain::start_chain(test.fakechain_router, true, recv_kill_in_start_chain, false).await?;

// Process each node
boot_nodes(
&nodes,
&test.fakechain_router,
&runtime_path,
&detached,
&mut master_node_port,
&anvil_process.as_ref().map(|ap| ap.id() as i32),
&vec![],
Arc::clone(&node_cleanup_infos),
&send_to_kill,
Arc::clone(&node_handles),
).await?;
info!("Done starting node to host dependencies.");

let url = format!("http://localhost:{port}");

for dependency_package_path in &test.dependency_package_paths {
let path = test_dir_path.join(&dependency_package_path).canonicalize()?;
build::execute(
&path,
false,
false,
false,
"test",
Some(url.clone()),
None,
false,
).await?;
start_package::execute(&path, &url).await?;
}

for setup_package in &setup_packages {
build::execute(
&setup_package.path,
false,
false,
false,
"test",
Some(url.clone()),
None,
false,
).await?;
}
for test_package_path in &test_package_paths {
build::execute(
&test_package_path,
false,
false,
false,
"test",
Some(url.clone()),
None,
false,
).await?;
}

info!("Cleaning up node to host dependencies.");
let _ = send_to_cleanup.send(false);

Ok((setup_packages, test_package_paths))
}

#[instrument(level = "trace", skip_all)]
async fn wait_until_booted(
node: &PathBuf,
Expand Down Expand Up @@ -507,47 +623,13 @@ async fn handle_test(
test_dir_path: &Path,
persist_home: bool,
) -> Result<()> {
let setup_packages: Vec<SetupPackage> = test
.setup_packages
.iter()
.cloned()
.map(|s| {
SetupPackage {
path: test_dir_path.join(s.path).canonicalize().unwrap(),
run: s.run,
}
})
.collect();
let test_package_paths: Vec<PathBuf> = test
.test_package_paths
.iter()
.cloned()
.map(|p| test_dir_path.join(p).canonicalize().unwrap())
.collect();
for setup_package in &setup_packages {
build::execute(
&setup_package.path,
false,
false,
false,
"test",
None,
None,
false,
).await?; // TODO
}
for test_package_path in &test_package_paths {
build::execute(
&test_package_path,
false,
false,
false,
"test",
None,
None,
false,
).await?; // TODO
}
let (setup_packages, test_package_paths) = build_packages(
&test,
test_dir_path,
&detached,
&persist_home,
runtime_path,
).await?;

let SetupCleanupReturn {
send_to_cleanup,
Expand Down

0 comments on commit 9c0e28a

Please sign in to comment.