Skip to content

Commit 9bf2968

Browse files
committed
add skeleton of a test for kpi-13 in orc
1 parent 8a11af1 commit 9bf2968

File tree

7 files changed

+73
-0
lines changed

7 files changed

+73
-0
lines changed

edgeless_api/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ grpc_impl = [
3333
"dep:prost",
3434
"tonic-build",
3535
]
36+
mocks = [] # used to enable mockall in edgeless_api for testing
3637

3738
[dependencies]
3839
anyhow = "1.0"
@@ -53,6 +54,7 @@ tokio = { version = "1", features = ["full"], optional = true }
5354
toml = "0.9.8"
5455
tonic = { version = "0.13", features = ["_tls-any"], optional = true }
5556
uuid = { version = "1.3", features = ["v4", "serde"] }
57+
mockall = "0.14"
5658

5759
[target.'cfg(not(target_os = "macos"))'.dependencies]
5860
rustls = { version = "0.23.32", features = ["ring"] }

edgeless_api/src/node_management.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub enum UpdatePeersRequest {
1010
Clear,
1111
}
1212

13+
#[cfg_attr(feature = "mocks", mockall::automock)]
1314
#[async_trait::async_trait]
1415
pub trait NodeManagementAPI: NodeManagementAPIClone + Sync + Send {
1516
async fn update_peers(&mut self, request: UpdatePeersRequest) -> anyhow::Result<()>;
@@ -33,3 +34,10 @@ impl Clone for Box<dyn NodeManagementAPI> {
3334
self.clone_box()
3435
}
3536
}
37+
38+
#[cfg(feature = "mocks")]
39+
impl NodeManagementAPIClone for MockNodeManagementAPI {
40+
fn clone_box(&self) -> Box<dyn NodeManagementAPI> {
41+
Box::new(MockNodeManagementAPI::new())
42+
}
43+
}

edgeless_api/src/outer/agent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-FileCopyrightText: © 2023 Claudio Cicconetti <c.cicconetti@iit.cnr.it>
33
// SPDX-FileCopyrightText: © 2023 Siemens AG
44
// SPDX-License-Identifier: MIT
5+
#[cfg_attr(feature = "mocks", mockall::automock)]
56
pub trait AgentAPI {
67
fn function_instance_api(&mut self) -> Box<dyn crate::function_instance::FunctionInstanceAPI<edgeless_api_core::instance_id::InstanceId>>;
78
fn node_management_api(&mut self) -> Box<dyn crate::node_management::NodeManagementAPI>;

edgeless_orc/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,9 @@ serial_test = { version = "3" }
4949
itertools = "0.13.0"
5050
chrono = "0.4.38"
5151
rustls = { version = "0.23.29", features = ["ring"] }
52+
53+
[dev-dependencies]
54+
mockall = "0.14"
55+
56+
[target.'cfg(test)'.dependencies]
57+
edgeless_api = {path = "../edgeless_api", features = ["mocks"]} # enable mocks in edgeless_api for tests

edgeless_orc/src/client_desc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct ClientDesc {
99
pub cordoned: bool,
1010
}
1111

12+
#[cfg_attr(test, mockall::automock)]
1213
impl ClientDesc {
1314
pub async fn from(request: &edgeless_api::node_registration::UpdateNodeRequest) -> anyhow::Result<Self> {
1415
// Return immediately if the node has an invalid agent or invocation URL.

edgeless_orc/src/orchestrator_task.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,3 +1187,57 @@ impl OrchestratorTask {
11871187
}
11881188
}
11891189
}
1190+
1191+
#[cfg(test)]
1192+
mod tests {
1193+
use super::*;
1194+
1195+
#[tokio::test]
1196+
async fn test_start_two_functions_then_stop_one() {
1197+
// channels
1198+
let (_tx, rx) = futures::channel::mpsc::unbounded();
1199+
let (subscriber_tx, _subscriber_rx) = futures::channel::mpsc::unbounded();
1200+
1201+
// mock proxy expectations setting
1202+
let mut mock_proxy = crate::proxy::MockProxy::new();
1203+
mock_proxy.expect_update_nodes().returning(|_| ());
1204+
mock_proxy.expect_update_resource_providers().returning(|_| ());
1205+
mock_proxy.expect_update_active_instances().returning(|_| ());
1206+
mock_proxy.expect_update_dependency_graph().returning(|_| ());
1207+
mock_proxy.expect_retrieve_deploy_intents().returning(|| vec![]);
1208+
1209+
// mock AgentAPI expectations
1210+
let mut mock_agent_api = edgeless_api::outer::agent::MockAgentAPI::new();
1211+
mock_agent_api.expect_node_management_api()
1212+
.returning(|| {
1213+
let mut mock_node_mgmt_api = edgeless_api::node_management::MockNodeManagementAPI::new();
1214+
mock_node_mgmt_api.expect_update_peers()
1215+
.returning(|_| Ok(()));
1216+
Box::new(mock_node_mgmt_api)
1217+
});
1218+
1219+
let proxy = std::sync::Arc::new(tokio::sync::Mutex::new(mock_proxy));
1220+
1221+
let settings = crate::EdgelessOrcBaselineSettings {
1222+
orchestration_strategy: crate::OrchestrationStrategy::RoundRobin,
1223+
};
1224+
1225+
let mut _orchestrator = OrchestratorTask::new(rx, settings, proxy.clone(), subscriber_tx).await;
1226+
1227+
// Add three nodes
1228+
let node_1_id = uuid::Uuid::new_v4();
1229+
let client_desc = crate::client_desc::ClientDesc {
1230+
agent_url: "http://node1/agent".to_string(),
1231+
invocation_url: "http://node1".to_string(),
1232+
capabilities: edgeless_api::node_registration::NodeCapabilities::default(),
1233+
cordoned: false,
1234+
api: Box::new(mock_agent_api),
1235+
};
1236+
let resource_providers = vec![];
1237+
_orchestrator.add_node(node_1_id, client_desc, resource_providers).await;
1238+
// test if it works
1239+
assert_eq!(1, 1);
1240+
}
1241+
}
1242+
1243+

edgeless_orc/src/proxy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub type NodeHealthStatuses = std::collections::HashMap<
2121
Vec<(chrono::DateTime<chrono::Utc>, edgeless_api::node_registration::NodeHealthStatus)>,
2222
>;
2323

24+
#[cfg_attr(test, mockall::automock)]
2425
#[async_trait::async_trait]
2526
pub trait Proxy: Sync + Send {
2627
/// Update the info on the currently actives nodes as given.

0 commit comments

Comments
 (0)