-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dc824e
commit 7a660c9
Showing
2 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
tests/message_passing/lazy_initialization/test_lazy_initialization.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from decimal import Decimal | ||
|
||
import pytest | ||
from temporalio import common | ||
from temporalio.client import ( | ||
Client, | ||
WithStartWorkflowOperation, | ||
) | ||
from temporalio.testing import WorkflowEnvironment | ||
from temporalio.worker import Worker | ||
|
||
from message_passing.update_with_start.lazy_initialization.workflows import ( | ||
ShoppingCartItem, | ||
ShoppingCartWorkflow, | ||
get_price, | ||
) | ||
|
||
|
||
async def test_shopping_cart_workflow(client: Client, env: WorkflowEnvironment): | ||
if env.supports_time_skipping: | ||
pytest.skip( | ||
"Java test server: https://github.com/temporalio/sdk-java/issues/1903" | ||
) | ||
async with Worker( | ||
client, | ||
task_queue="lazy-initialization-test", | ||
workflows=[ShoppingCartWorkflow], | ||
activities=[get_price], | ||
): | ||
cart_id = "cart--session-1234" | ||
make_start_op = lambda: WithStartWorkflowOperation( | ||
ShoppingCartWorkflow.run, | ||
id=cart_id, | ||
id_conflict_policy=common.WorkflowIDConflictPolicy.USE_EXISTING, | ||
task_queue="lazy-initialization-test", | ||
) | ||
start_op_1 = make_start_op() | ||
price = Decimal( | ||
await client.execute_update_with_start_workflow( | ||
ShoppingCartWorkflow.add_item, | ||
ShoppingCartItem(sku="item-1", quantity=2), | ||
start_workflow_operation=start_op_1, | ||
) | ||
) | ||
|
||
assert price == Decimal("11.98") | ||
|
||
workflow_handle = await start_op_1.workflow_handle() | ||
|
||
start_op_2 = make_start_op() | ||
price = Decimal( | ||
await client.execute_update_with_start_workflow( | ||
ShoppingCartWorkflow.add_item, | ||
ShoppingCartItem(sku="item-2", quantity=1), | ||
start_workflow_operation=start_op_2, | ||
) | ||
) | ||
assert price == Decimal("17.97") | ||
|
||
workflow_handle = await start_op_2.workflow_handle() | ||
|
||
await workflow_handle.signal(ShoppingCartWorkflow.checkout) | ||
|
||
finalized_order = await workflow_handle.result() | ||
assert finalized_order.items == [ | ||
(ShoppingCartItem(sku="item-1", quantity=2), "11.98"), | ||
(ShoppingCartItem(sku="item-2", quantity=1), "5.99"), | ||
] | ||
assert finalized_order.total == "17.97" |