Skip to content

Commit 3f005e5

Browse files
authored
feat(session): add tests for session deletion (#179)
# Description Add tests for session deletion. Signed-off-by: Mauro Sardara <[email protected]>
1 parent 956da18 commit 3f005e5

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

Diff for: data-plane/gateway/service/src/fire_and_forget.rs

+19
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,23 @@ mod tests {
173173
assert_eq!(msg.message, message);
174174
assert_eq!(msg.info.id, 1);
175175
}
176+
177+
#[tokio::test]
178+
async fn test_session_delete() {
179+
let (tx_gw, _) = tokio::sync::mpsc::channel(1);
180+
let (tx_app, _) = tokio::sync::mpsc::channel(1);
181+
182+
let source = Agent::from_strings("cisco", "default", "local_agent", 0);
183+
184+
{
185+
let _session = FireAndForget::new(
186+
0,
187+
FireAndForgetConfiguration {},
188+
SessionDirection::Bidirectional,
189+
source,
190+
tx_gw,
191+
tx_app,
192+
);
193+
}
194+
}
176195
}

Diff for: data-plane/gateway/service/src/request_response.rs

+24
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,28 @@ mod tests {
369369
_ => panic!("unexpected error"),
370370
}
371371
}
372+
373+
#[tokio::test]
374+
async fn test_session_delete() {
375+
let (tx_gw, _) = tokio::sync::mpsc::channel(1);
376+
let (tx_app, _) = tokio::sync::mpsc::channel(1);
377+
378+
let session_config = RequestResponseConfiguration {
379+
max_retries: 0,
380+
timeout: std::time::Duration::from_millis(1000),
381+
};
382+
383+
let source = Agent::from_strings("cisco", "default", "local_agent", 0);
384+
385+
{
386+
let _session = RequestResponse::new(
387+
0,
388+
session_config,
389+
SessionDirection::Bidirectional,
390+
source,
391+
tx_gw,
392+
tx_app,
393+
);
394+
}
395+
}
372396
}

Diff for: data-plane/gateway/service/src/session_layer.rs

+24
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,30 @@ mod tests {
402402
assert!(res.is_ok());
403403
}
404404

405+
#[tokio::test]
406+
async fn test_delete_session() {
407+
let (tx_gw, _) = tokio::sync::mpsc::channel(1);
408+
let (tx_app, _) = tokio::sync::mpsc::channel(1);
409+
let agent = Agent::from_strings("org", "ns", "type", 0);
410+
411+
let session_layer = SessionLayer::new(&agent, 0, tx_gw.clone(), tx_app.clone());
412+
413+
let res = session_layer
414+
.create_session(
415+
SessionConfig::FireAndForget(FireAndForgetConfiguration {}),
416+
Some(1),
417+
)
418+
.await;
419+
assert!(res.is_ok());
420+
421+
let res = session_layer.remove_session(1).await;
422+
assert!(res);
423+
424+
// try to delete a non-existing session
425+
let res = session_layer.remove_session(1).await;
426+
assert!(!res);
427+
}
428+
405429
#[tokio::test]
406430
async fn test_handle_message() {
407431
let (tx_gw, _) = tokio::sync::mpsc::channel(1);

Diff for: data-plane/gateway/service/src/streaming.rs

+36
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,11 @@ impl Streaming {
412412
}
413413
}
414414
}
415+
416+
debug!(
417+
"stopping message processing on streaming session {}",
418+
session_id
419+
);
415420
});
416421
}
417422
}
@@ -1360,4 +1365,35 @@ mod tests {
13601365
)
13611366
);
13621367
}
1368+
1369+
#[tokio::test]
1370+
#[traced_test]
1371+
async fn test_session_delete() {
1372+
let (tx_gw, _) = tokio::sync::mpsc::channel(1);
1373+
let (tx_app, _) = tokio::sync::mpsc::channel(1);
1374+
1375+
let source = Agent::from_strings("cisco", "default", "local_agent", 0);
1376+
1377+
let session_config: StreamingConfiguration =
1378+
StreamingConfiguration::new(SessionDirection::Sender, None, None, None);
1379+
1380+
{
1381+
let _session = Streaming::new(
1382+
0,
1383+
session_config.clone(),
1384+
SessionDirection::Sender,
1385+
source.clone(),
1386+
tx_gw.clone(),
1387+
tx_app.clone(),
1388+
);
1389+
}
1390+
1391+
// session should be deleted, make sure the process loop is also closed
1392+
time::sleep(Duration::from_millis(100)).await;
1393+
1394+
// check that the session is deleted, by checking the log
1395+
assert!(logs_contain(
1396+
"stopping message processing on streaming session 0"
1397+
));
1398+
}
13631399
}

0 commit comments

Comments
 (0)