Skip to content

Commit 884b25f

Browse files
committed
test: if config_snapshot is handled concurrently
To be more sure about future changes to the c8y mapper and the converter, we need tests checking that operations happen concurrently. This change introduces a test that only covers config_snapshot operation, but it expectedly fails when regressions were introduced by the previous commits in this PR. Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
1 parent 74aced6 commit 884b25f

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

  • crates/extensions/c8y_mapper_ext/src

crates/extensions/c8y_mapper_ext/src/tests.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,6 +2418,50 @@ async fn c8y_mapper_nested_child_service_event_mapping_to_smartrest() {
24182418
.await;
24192419
}
24202420

2421+
#[tokio::test]
2422+
async fn mapper_processes_operations_concurrently() {
2423+
let num_operations = 100;
2424+
2425+
let mut fts_server = mockito::Server::new();
2426+
let mock = fts_server
2427+
.mock(
2428+
"GET",
2429+
"/tedge/file-transfer/test-device/config_snapshot/c8y-mapper-1234",
2430+
)
2431+
// make each download block so it doesn't complete before we submit all operations
2432+
.with_chunked_body(|_w| {
2433+
std::thread::sleep(Duration::from_secs(5));
2434+
Ok(())
2435+
})
2436+
.expect(num_operations)
2437+
.create_async()
2438+
.await;
2439+
let host_port = fts_server.host_with_port();
2440+
2441+
let cfg_dir = TempTedgeDir::new();
2442+
let (mqtt, http, _fs, _timer, _ul, _dl) = spawn_c8y_mapper_actor(&cfg_dir, true).await;
2443+
spawn_dummy_c8y_http_proxy(http);
2444+
2445+
let mut mqtt = mqtt.with_timeout(TEST_TIMEOUT_MS);
2446+
skip_init_messages(&mut mqtt).await;
2447+
2448+
// simulate many successful operations that needs to be handled by the mapper
2449+
for i in 0..num_operations {
2450+
mqtt.send(MqttMessage::new(
2451+
&Topic::new_unchecked(&format!("te/device/main///cmd/config_snapshot/c8y-mapper-{i}")),
2452+
json!({
2453+
"status": "successful",
2454+
"tedgeUrl": format!("http://{host_port}/tedge/file-transfer/test-device/config_snapshot/c8y-mapper-1234"),
2455+
"type": "path/type/A",
2456+
})
2457+
.to_string(),
2458+
))
2459+
.await.unwrap();
2460+
}
2461+
2462+
mock.assert();
2463+
}
2464+
24212465
fn assert_command_exec_log_content(cfg_dir: TempTedgeDir, expected_contents: &str) {
24222466
let paths = fs::read_dir(cfg_dir.to_path_buf().join("agent")).unwrap();
24232467
for path in paths {

0 commit comments

Comments
 (0)