|
1 | 1 | use std::time::Instant; |
2 | | -use std::time::{SystemTime, UNIX_EPOCH}; |
3 | 2 |
|
4 | 3 | use futures_lite::StreamExt; |
5 | 4 | use prost::Message; |
6 | 5 | use taurus_core::runtime::engine::{EmitType, ExecutionEngine, ExecutionId, RespondEmitter}; |
| 6 | +use taurus_core::time::now_unix_ms; |
7 | 7 | use taurus_core::types::errors::runtime_error::RuntimeError; |
8 | 8 | use taurus_core::types::signal::Signal; |
9 | 9 | use taurus_provider::providers::emitter::nats_emitter::NATSRespondEmitter; |
@@ -37,15 +37,15 @@ pub fn spawn_worker( |
37 | 37 | }; |
38 | 38 |
|
39 | 39 | let mut test_execution_subscription = match client |
40 | | - .queue_subscribe(String::from("test_executions.*"), "taurus".into()) |
| 40 | + .queue_subscribe(String::from("test_execution.*"), "taurus".into()) |
41 | 41 | .await |
42 | 42 | { |
43 | 43 | Ok(subscription) => { |
44 | | - log::info!("Subscribed to 'test_executions.*'"); |
| 44 | + log::info!("Subscribed to 'test_execution.*'"); |
45 | 45 | subscription |
46 | 46 | } |
47 | 47 | Err(err) => { |
48 | | - log::error!("Failed to subscribe to 'test_executions.*': {:?}", err); |
| 48 | + log::error!("Failed to subscribe to 'test_execution.*': {:?}", err); |
49 | 49 | return; |
50 | 50 | } |
51 | 51 | }; |
@@ -85,7 +85,7 @@ pub fn spawn_worker( |
85 | 85 | } |
86 | 86 | None => { |
87 | 87 | test_execution_closed = true; |
88 | | - log::warn!("Subscription 'test_executions.*' ended"); |
| 88 | + log::warn!("Subscription 'test_execution.*' ended"); |
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
@@ -158,8 +158,16 @@ async fn process_test_execution_message( |
158 | 158 | nats_remote: &NATSRemoteRuntime, |
159 | 159 | runtime_usage_service: Option<&TaurusRuntimeUsageService>, |
160 | 160 | ) { |
| 161 | + if message.reply.is_none() { |
| 162 | + log::warn!( |
| 163 | + "Received test execution request without reply subject on '{}'; ignoring request", |
| 164 | + message.subject |
| 165 | + ); |
| 166 | + return; |
| 167 | + } |
| 168 | + |
161 | 169 | let requested_execution_id = |
162 | | - match parse_execution_id_from_subject(&message.subject, "test_executions") { |
| 170 | + match parse_execution_id_from_subject(&message.subject, "test_execution") { |
163 | 171 | Some(res) => res, |
164 | 172 | None => { |
165 | 173 | log::error!("Failed to extract execution uuid from {}", &message.subject); |
@@ -335,13 +343,6 @@ async fn respond_to_test_execution_request( |
335 | 343 | } |
336 | 344 | } |
337 | 345 |
|
338 | | -fn now_unix_ms() -> i64 { |
339 | | - SystemTime::now() |
340 | | - .duration_since(UNIX_EPOCH) |
341 | | - .map(|it| it.as_millis() as i64) |
342 | | - .unwrap_or(0) |
343 | | -} |
344 | | - |
345 | 346 | #[cfg(test)] |
346 | 347 | mod tests { |
347 | 348 | use super::*; |
@@ -381,7 +382,6 @@ mod tests { |
381 | 382 | runtime().block_on(async { |
382 | 383 | let client = connect_test_nats().await; |
383 | 384 | let worker = spawn_test_worker(client.clone()); |
384 | | - wait_for_worker_subscription().await; |
385 | 385 |
|
386 | 386 | let execution_id = ExecutionId::new_v4(); |
387 | 387 | let fixture = load_fixture("flows/01_return_object.json"); |
@@ -418,7 +418,6 @@ mod tests { |
418 | 418 | runtime().block_on(async { |
419 | 419 | let client = connect_test_nats().await; |
420 | 420 | let worker = spawn_test_worker(client.clone()); |
421 | | - wait_for_worker_subscription().await; |
422 | 421 |
|
423 | 422 | let execution_id = ExecutionId::new_v4(); |
424 | 423 | let response = |
@@ -471,16 +470,12 @@ mod tests { |
471 | 470 | spawn_worker(client, engine, nats_remote, runtime_emitter, None) |
472 | 471 | } |
473 | 472 |
|
474 | | - async fn wait_for_worker_subscription() { |
475 | | - tokio::time::sleep(Duration::from_millis(250)).await; |
476 | | - } |
477 | | - |
478 | 473 | async fn request_execution_result( |
479 | 474 | client: &async_nats::Client, |
480 | 475 | execution_id: ExecutionId, |
481 | 476 | payload: Vec<u8>, |
482 | 477 | ) -> Result<ExecutionResult, String> { |
483 | | - let subject = format!("test_executions.{execution_id}"); |
| 478 | + let subject = format!("test_execution.{execution_id}"); |
484 | 479 |
|
485 | 480 | for attempt in 1..=10 { |
486 | 481 | match tokio::time::timeout( |
|
0 commit comments