Skip to content

Commit 07d5782

Browse files
committed
fix tests & rm ignore on some cases
1 parent 6ef4de6 commit 07d5782

File tree

8 files changed

+46
-98
lines changed

8 files changed

+46
-98
lines changed

compute/src/node/gossipsub.rs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -147,61 +147,3 @@ impl DriaComputeNode {
147147
}
148148
}
149149
}
150-
151-
#[cfg(test)]
152-
mod tests {
153-
use super::*;
154-
use crate::DriaComputeNodeConfig;
155-
use tokio::time::sleep;
156-
use tokio_util::sync::CancellationToken;
157-
158-
// FIXME: test is failing
159-
#[tokio::test]
160-
#[ignore = "run this manually"]
161-
async fn test_publish_message() -> eyre::Result<()> {
162-
let _ = env_logger::builder()
163-
.filter_level(log::LevelFilter::Off)
164-
.filter_module("dkn_compute", log::LevelFilter::Debug)
165-
.filter_module("dkn_p2p", log::LevelFilter::Debug)
166-
.is_test(true)
167-
.try_init();
168-
169-
// create node
170-
let cancellation = CancellationToken::new();
171-
let config = DriaComputeNodeConfig::default();
172-
let (mut node, p2p, _, _) = DriaComputeNode::new(config).await?;
173-
174-
// spawn p2p task
175-
let p2p_task = tokio::spawn(async move { p2p.run().await });
176-
177-
// launch & wait for a while for connections
178-
let run_cancellation = cancellation.clone();
179-
let wait_duration = tokio::time::Duration::from_secs(20);
180-
log::info!(
181-
"Waiting a bit ({}ms) for peer setup.",
182-
wait_duration.as_millis()
183-
);
184-
sleep(wait_duration).await;
185-
tokio::select! {
186-
_ = node.run(run_cancellation) => (),
187-
_ = tokio::time::sleep(wait_duration) => cancellation.cancel(),
188-
}
189-
log::info!("Connected Peers:\n{:#?}", node.peers().await?);
190-
191-
// publish a dummy message
192-
let topic = "foo";
193-
let message = node.new_message("hello from the other side", topic);
194-
node.subscribe(topic).await?;
195-
node.publish(message).await?;
196-
node.unsubscribe(topic).await?;
197-
198-
// close everything
199-
log::info!("Shutting down node.");
200-
node.p2p.shutdown().await?;
201-
202-
// wait for task handle
203-
p2p_task.await?;
204-
205-
Ok(())
206-
}
207-
}

compute/src/utils/crypto.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,4 @@ mod tests {
114114
"could not verify signature"
115115
);
116116
}
117-
118-
#[test]
119-
#[ignore = "run only with profiler if wanted"]
120-
fn test_memory_usage() {
121-
let secret_key =
122-
SecretKey::parse_slice(DUMMY_SECRET_KEY).expect("to parse private key slice");
123-
let public_key = PublicKey::from_secret_key(&secret_key);
124-
125-
// sign the message using the secret key
126-
let digest = sha256hash(MESSAGE);
127-
let message = Message::parse_slice(&digest).expect("to parse message");
128-
let (signature, _) = sign(&message, &secret_key);
129-
130-
// verify signature with context
131-
for _ in 0..1_000_000 {
132-
let ok = verify(&message, &signature, &public_key);
133-
assert!(ok);
134-
}
135-
}
136117
}

compute/src/utils/nodes.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,19 @@ mod tests {
5656
use super::*;
5757

5858
#[tokio::test]
59-
#[ignore = "run this manually"]
6059
async fn test_refresh_dria_nodes() {
6160
let mut nodes = DriaNodes::new(DriaNetworkType::Community);
6261
refresh_dria_nodes(&mut nodes).await.unwrap();
63-
println!("Community: {:#?}", nodes);
62+
assert!(!nodes.bootstrap_nodes.is_empty());
63+
assert!(!nodes.relay_nodes.is_empty());
64+
assert!(!nodes.rpc_nodes.is_empty());
65+
assert!(!nodes.rpc_peerids.is_empty());
6466

6567
let mut nodes = DriaNodes::new(DriaNetworkType::Pro);
6668
refresh_dria_nodes(&mut nodes).await.unwrap();
67-
println!("Pro: {:#?}", nodes);
69+
assert!(!nodes.bootstrap_nodes.is_empty());
70+
assert!(!nodes.relay_nodes.is_empty());
71+
assert!(!nodes.rpc_nodes.is_empty());
72+
assert!(!nodes.rpc_peerids.is_empty());
6873
}
6974
}

compute/src/utils/specs.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,18 @@ mod tests {
8484
use super::*;
8585

8686
#[tokio::test]
87-
#[ignore = "run manually"]
8887
async fn test_print_specs() {
8988
let mut spec_collector = SpecCollector::new(vec!["gpt-4o".to_string()]);
9089
let specs = spec_collector.collect().await;
91-
println!("{}", serde_json::to_string_pretty(&specs).unwrap());
90+
assert!(specs.total_mem > 0);
91+
assert!(specs.free_mem > 0);
92+
assert!(specs.num_cpus.is_some());
93+
assert!(specs.cpu_usage > 0.0);
94+
assert!(!specs.os.is_empty());
95+
assert!(!specs.arch.is_empty());
96+
assert!(specs.lookup.is_some());
97+
98+
// print optionally:
99+
// println!("{}", serde_json::to_string_pretty(&specs).unwrap());
92100
}
93101
}

p2p/tests/gossipsub_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async fn test_gossipsub() -> Result<()> {
1919
.filter_level(log::LevelFilter::Off)
2020
.filter_module("gossipsub_test", log::LevelFilter::Debug)
2121
.filter_module("dkn_p2p", log::LevelFilter::Debug)
22-
.is_test(true)
22+
// .is_test(true)
2323
.try_init();
2424

2525
let listen_addr = "/ip4/0.0.0.0/tcp/4001".parse()?;

workflows/src/config.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,13 @@ impl DriaWorkflowsConfig {
202202
}
203203

204204
/// Check if the required compute services are running.
205-
/// This has several steps:
206205
///
207206
/// - If Ollama models are used, hardcoded models are checked locally, and for
208207
/// external models, the workflow is tested with a simple task with timeout.
209-
/// - If OpenAI models are used, the API key is checked and the models are tested
208+
/// - If API based models are used, the API key is checked and the models are tested with a dummy request.
210209
///
211-
/// If both type of models are used, both services are checked.
212210
/// In the end, bad models are filtered out and we simply check if we are left if any valid models at all.
213-
/// If not, an error is returned.
211+
/// If there are no models left in the end, an error is thrown.
214212
pub async fn check_services(&mut self) -> Result<()> {
215213
log::info!("Checking configured services.");
216214

workflows/tests/models_test.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use dkn_workflows::{DriaWorkflowsConfig, Model, ModelProvider};
22
use eyre::Result;
33

4+
#[inline(always)]
45
fn setup() {
56
// read api key from .env
67
let _ = dotenvy::dotenv();
78

89
// set logger
910
let _ = env_logger::builder()
10-
.parse_filters("none,dkn_workflows=debug")
11+
.filter_level(log::LevelFilter::Off)
12+
.filter_module("models_test", log::LevelFilter::Debug)
13+
.filter_module("dkn_workflows", log::LevelFilter::Debug)
1114
.is_test(true)
1215
.try_init();
1316
}
@@ -61,6 +64,22 @@ async fn test_gemini_check() -> Result<()> {
6164
Ok(())
6265
}
6366

67+
#[tokio::test]
68+
#[ignore = "requires OpenRouter"]
69+
async fn test_openrouter_check() -> Result<()> {
70+
setup();
71+
72+
let models = vec![Model::ORDeepSeek2_5];
73+
let mut model_config = DriaWorkflowsConfig::new(models);
74+
model_config.check_services().await?;
75+
76+
assert_eq!(
77+
model_config.models[0],
78+
(ModelProvider::OpenRouter, Model::ORDeepSeek2_5)
79+
);
80+
Ok(())
81+
}
82+
6483
#[tokio::test]
6584
async fn test_empty() {
6685
assert!(DriaWorkflowsConfig::new(vec![])

workflows/tests/parse_test.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use dkn_workflows::Workflow;
22

33
#[test]
4-
fn test_parse_example() -> eyre::Result<()> {
4+
fn test_parse_example() {
55
let object = serde_json::json!({
66
"config":{
77
"max_steps":50,
@@ -70,13 +70,7 @@ fn test_parse_example() -> eyre::Result<()> {
7070
}
7171
],
7272
"schema":null,
73-
"inputs":[
74-
75-
],
7673
"operator":"end",
77-
"outputs":[
78-
79-
]
8074
}
8175
],
8276
"steps":[
@@ -99,7 +93,8 @@ fn test_parse_example() -> eyre::Result<()> {
9993
}
10094
});
10195

102-
serde_json::from_value::<Workflow>(object)?;
103-
104-
Ok(())
96+
assert!(
97+
serde_json::from_value::<Workflow>(object).is_ok(),
98+
"could not parse"
99+
);
105100
}

0 commit comments

Comments
 (0)