Skip to content

Commit 683ca80

Browse files
committed
refactor: Add Processed flag on matching await-next with all-processed
1 parent eed87a0 commit 683ca80

4 files changed

Lines changed: 93 additions & 4 deletions

File tree

crates/testing/test-programs/stub/workflow/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::obelisk::workflow::workflow_support::{self, ClosingStrategy};
33
use crate::testing::stub_activity::activity;
44
use crate::testing::stub_activity_obelisk_ext::activity as activity_ext;
55
use crate::testing::stub_activity_obelisk_stub::activity as activity_stub;
6-
use obelisk::types::execution::{ExecutionId, StubError};
6+
use obelisk::types::execution::{ExecutionError, ExecutionId, StubError};
77
use wit_bindgen::generate;
88

99
generate!({ generate_all });
@@ -17,7 +17,7 @@ impl Guest for Component {
1717
activity_stub::foo_stub(&execution_id, Ok(&format!("stubbing {arg}")))
1818
.expect("stubbed activity must accept returned value once");
1919
let (actual_execution_id, ret_val) =
20-
activity_ext::foo_await_next(&join_set).expect("stubbed activity must resolve");
20+
activity_ext::foo_await_next(&join_set).expect("stubbed execution result above");
2121
assert_eq!(execution_id.id, actual_execution_id.id);
2222
ret_val
2323
}
@@ -67,4 +67,12 @@ impl Guest for Component {
6767
fn stub_subworkflow(execution_id: ExecutionId, retval: String) -> Result<(), StubError> {
6868
activity_stub::foo_stub(&execution_id, Ok(&format!("stubbing {retval}")))
6969
}
70+
71+
fn await_next_produces_all_processed_error() {
72+
let join_set = workflow_support::new_join_set_generated(ClosingStrategy::Complete);
73+
let ExecutionError::AllProcessed = activity_ext::foo_await_next(&join_set).unwrap_err()
74+
else {
75+
unreachable!()
76+
};
77+
}
7078
}

crates/testing/test-programs/stub/workflow/wit/deps/testing_stub-workflow/stub-workflow.wit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ interface workflow {
1010

1111
submit-race: func() -> string;
1212
stub-subworkflow: func(execution-id: execution-id, retval: string) -> result<_, stub-error>;
13+
14+
await-next-produces-all-processed-error: func();
1315
}

crates/wasm-workers/src/workflow/event_history.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ impl EventHistory {
706706
&& Some(requested_ffqn) == found_requested_ffqn.as_ref() =>
707707
{
708708
trace!(%join_set_id, "matched JoinNextChild with JoinNextTooMany");
709+
self.event_history[found_idx].1 = Processed;
709710
let all_processed = ExecutionErrorVariant::AllProcessed.as_wast_val();
710711
Ok(FindMatchingResponse::Found(ChildReturnValue::WastVal(
711712
WastVal::Result(Err(Some(Box::new(all_processed)))),

crates/wasm-workers/src/workflow/workflow_worker.rs

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ impl<C: ClockFn + 'static, S: Sleep + 'static> Worker for WorkflowWorker<C, S> {
689689
#[cfg(test)]
690690
pub(crate) mod tests {
691691
use super::*;
692+
use crate::activity::activity_worker::tests::compile_activity_stub;
692693
use crate::{
693694
activity::activity_worker::tests::{
694695
FIBO_10_INPUT, FIBO_10_OUTPUT, compile_activity, spawn_activity_fibo, wasm_file_name,
@@ -1772,8 +1773,6 @@ pub(crate) mod tests {
17721773
async fn stub(
17731774
#[values(db_tests::Database::Memory, db_tests::Database::Sqlite)] db: db_tests::Database,
17741775
) {
1775-
use crate::activity::activity_worker::tests::compile_activity_stub;
1776-
17771776
const FFQN_WORKFLOW_STUB: FunctionFqn = FunctionFqn::new_static_tuple(
17781777
test_programs_stub_workflow_builder::exports::testing::stub_workflow::workflow::SUBMIT_STUB_AWAIT,
17791778
);
@@ -1997,4 +1996,83 @@ pub(crate) mod tests {
19971996
drop(exec_task);
19981997
db_pool.close().await.unwrap();
19991998
}
1999+
2000+
#[rstest::rstest]
2001+
#[tokio::test]
2002+
async fn await_next_produces_all_processed_error(
2003+
#[values(db_tests::Database::Memory, db_tests::Database::Sqlite)] db: db_tests::Database,
2004+
) {
2005+
const FFQN: FunctionFqn = FunctionFqn::new_static_tuple(
2006+
test_programs_stub_workflow_builder::exports::testing::stub_workflow::workflow::AWAIT_NEXT_PRODUCES_ALL_PROCESSED_ERROR
2007+
);
2008+
test_utils::set_up();
2009+
let sim_clock = SimClock::epoch();
2010+
let (_guard, db_pool) = db.set_up().await;
2011+
let fn_registry = TestingFnRegistry::new_from_components(vec![
2012+
compile_activity_stub(test_programs_stub_activity_builder::TEST_PROGRAMS_STUB_ACTIVITY),
2013+
compile_workflow(test_programs_stub_workflow_builder::TEST_PROGRAMS_STUB_WORKFLOW),
2014+
]);
2015+
2016+
let worker = compile_workflow_worker(
2017+
test_programs_stub_workflow_builder::TEST_PROGRAMS_STUB_WORKFLOW,
2018+
db_pool.clone(),
2019+
sim_clock.clone(),
2020+
TokioSleep,
2021+
JoinNextBlockingStrategy::Interrupt,
2022+
&fn_registry,
2023+
);
2024+
let exec_task = ExecTask::new(
2025+
worker,
2026+
ExecConfig {
2027+
batch_size: 1,
2028+
lock_expiry: Duration::from_secs(1),
2029+
tick_sleep: TICK_SLEEP,
2030+
component_id: ComponentId::dummy_workflow(),
2031+
task_limiter: None,
2032+
executor_id: ExecutorId::generate(),
2033+
},
2034+
sim_clock.clone(),
2035+
db_pool.clone(),
2036+
Arc::new([FFQN]),
2037+
);
2038+
2039+
let execution_id = ExecutionId::generate();
2040+
let db_connection = db_pool.connection();
2041+
db_connection
2042+
.create(CreateRequest {
2043+
created_at: sim_clock.now(),
2044+
execution_id: execution_id.clone(),
2045+
ffqn: FFQN,
2046+
params: Params::empty(),
2047+
parent: None,
2048+
metadata: concepts::ExecutionMetadata::empty(),
2049+
scheduled_at: sim_clock.now(),
2050+
retry_exp_backoff: Duration::ZERO,
2051+
max_retries: u32::MAX,
2052+
component_id: ComponentId::dummy_workflow(),
2053+
scheduled_by: None,
2054+
})
2055+
.await
2056+
.unwrap();
2057+
2058+
{
2059+
let task_count = exec_task
2060+
.tick_test(sim_clock.now(), RunId::generate())
2061+
.await
2062+
.unwrap()
2063+
.wait_for_tasks()
2064+
.await
2065+
.unwrap();
2066+
assert_eq!(1, task_count);
2067+
}
2068+
2069+
let res = db_connection.get(&execution_id).await.unwrap();
2070+
assert_matches!(
2071+
res.into_finished_result().unwrap().unwrap(),
2072+
SupportedFunctionReturnValue::None
2073+
);
2074+
2075+
drop(exec_task);
2076+
db_pool.close().await.unwrap();
2077+
}
20002078
}

0 commit comments

Comments
 (0)