|
1 | | -use crate::{test_help::canned_histories, worker::ManagedWFFunc}; |
| 1 | +use crate::{ |
| 2 | + test_help::{ |
| 3 | + build_mock_pollers, canned_histories, hist_to_poll_resp, mock_worker, MockPollCfg, |
| 4 | + }, |
| 5 | + worker::{client::mocks::mock_workflow_client, ManagedWFFunc, LEGACY_QUERY_ID}, |
| 6 | +}; |
2 | 7 | use rstest::{fixture, rstest}; |
3 | | -use std::time::Duration; |
| 8 | +use std::{collections::VecDeque, time::Duration}; |
4 | 9 | use temporal_sdk::{WfContext, WorkflowFunction}; |
5 | | -use temporal_sdk_core_protos::temporal::api::enums::v1::CommandType; |
| 10 | +use temporal_sdk_core_api::Worker; |
| 11 | +use temporal_sdk_core_protos::{ |
| 12 | + coresdk::{ |
| 13 | + workflow_commands::{workflow_command::Variant::RespondToQuery, QueryResult, QuerySuccess}, |
| 14 | + workflow_completion::WorkflowActivationCompletion, |
| 15 | + }, |
| 16 | + temporal::api::{enums::v1::CommandType, query::v1::WorkflowQuery}, |
| 17 | +}; |
| 18 | +use temporal_sdk_core_test_utils::start_timer_cmd; |
6 | 19 |
|
7 | 20 | fn timers_wf(num_timers: u32) -> WorkflowFunction { |
8 | 21 | WorkflowFunction::new(move |command_sink: WfContext| async move { |
@@ -63,3 +76,60 @@ async fn replay_flag_is_correct_partial_history() { |
63 | 76 | assert_eq!(commands[0].command_type, CommandType::StartTimer as i32); |
64 | 77 | wfm.shutdown().await.unwrap(); |
65 | 78 | } |
| 79 | + |
| 80 | +#[tokio::test] |
| 81 | +async fn replay_flag_correct_with_query() { |
| 82 | + let wfid = "fake_wf_id"; |
| 83 | + let t = canned_histories::single_timer("1"); |
| 84 | + let tasks = VecDeque::from(vec![ |
| 85 | + { |
| 86 | + let mut pr = hist_to_poll_resp(&t, wfid.to_owned(), 2.into()); |
| 87 | + // Server can issue queries that contain the WFT completion and the subsequent |
| 88 | + // commands, but not the consequences yet. |
| 89 | + pr.query = Some(WorkflowQuery { |
| 90 | + query_type: "query-type".to_string(), |
| 91 | + query_args: Some(b"hi".into()), |
| 92 | + header: None, |
| 93 | + }); |
| 94 | + let h = pr.history.as_mut().unwrap(); |
| 95 | + h.events.truncate(5); |
| 96 | + pr.started_event_id = 3; |
| 97 | + dbg!(&pr.resp); |
| 98 | + pr |
| 99 | + }, |
| 100 | + hist_to_poll_resp(&t, wfid.to_owned(), 2.into()), |
| 101 | + ]); |
| 102 | + let mut mock = MockPollCfg::from_resp_batches(wfid, t, tasks, mock_workflow_client()); |
| 103 | + mock.num_expected_legacy_query_resps = 1; |
| 104 | + let mut mock = build_mock_pollers(mock); |
| 105 | + mock.worker_cfg(|wc| wc.max_cached_workflows = 10); |
| 106 | + let core = mock_worker(mock); |
| 107 | + |
| 108 | + let task = core.poll_workflow_activation().await.unwrap(); |
| 109 | + core.complete_workflow_activation(WorkflowActivationCompletion::from_cmd( |
| 110 | + task.run_id, |
| 111 | + start_timer_cmd(1, Duration::from_secs(1)), |
| 112 | + )) |
| 113 | + .await |
| 114 | + .unwrap(); |
| 115 | + |
| 116 | + let task = core.poll_workflow_activation().await.unwrap(); |
| 117 | + assert!(task.is_replaying); |
| 118 | + core.complete_workflow_activation(WorkflowActivationCompletion::from_cmd( |
| 119 | + task.run_id, |
| 120 | + RespondToQuery(QueryResult { |
| 121 | + query_id: LEGACY_QUERY_ID.to_string(), |
| 122 | + variant: Some( |
| 123 | + QuerySuccess { |
| 124 | + response: Some("hi".into()), |
| 125 | + } |
| 126 | + .into(), |
| 127 | + ), |
| 128 | + }), |
| 129 | + )) |
| 130 | + .await |
| 131 | + .unwrap(); |
| 132 | + |
| 133 | + let task = core.poll_workflow_activation().await.unwrap(); |
| 134 | + assert!(!task.is_replaying); |
| 135 | +} |
0 commit comments