Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Dec 19, 2024
1 parent 1dc824e commit 7a660c9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def event_loop():
async def env(request) -> AsyncGenerator[WorkflowEnvironment, None]:
env_type = request.config.getoption("--workflow-environment")
if env_type == "local":
env = await WorkflowEnvironment.start_local()
env = await WorkflowEnvironment.start_local(
dev_server_extra_args=[
"--dynamic-config-value",
"frontend.enableExecuteMultiOperation=true",
]
)
elif env_type == "time-skipping":
env = await WorkflowEnvironment.start_time_skipping()
else:
Expand Down
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"

0 comments on commit 7a660c9

Please sign in to comment.