@@ -3934,6 +3934,73 @@ async def test_workflow_uuid(client: Client):
39343934 assert handle2_query_result == await handle2 .query (UUIDWorkflow .result )
39353935
39363936
3937+ @workflow .defn
3938+ class UUID7Workflow :
3939+ def __init__ (self ) -> None :
3940+ self ._result = "<unset>"
3941+ self ._time_ms = - 1
3942+
3943+ @workflow .run
3944+ async def run (self ) -> None :
3945+ self ._time_ms = workflow .time_ns () // 1_000_000
3946+ self ._result = str (workflow .uuid7 ())
3947+
3948+ @workflow .query
3949+ def result (self ) -> str :
3950+ return self ._result
3951+
3952+ @workflow .query
3953+ def time_ms (self ) -> int :
3954+ return self ._time_ms
3955+
3956+
3957+ async def test_workflow_uuid7 (client : Client ):
3958+ task_queue = str (uuid .uuid4 ())
3959+ async with new_worker (
3960+ client , UUID7Workflow , task_queue = task_queue , max_cached_workflows = 0
3961+ ):
3962+ # Get two handle UUID results. Need to disable workflow cache since we
3963+ # restart the worker and don't want to pay the sticky queue penalty.
3964+ handle1 = await client .start_workflow (
3965+ UUID7Workflow .run , id = f"workflow-{ uuid .uuid4 ()} " , task_queue = task_queue
3966+ )
3967+ await handle1 .result ()
3968+ handle1_query_result = await handle1 .query (UUID7Workflow .result )
3969+
3970+ handle2 = await client .start_workflow (
3971+ UUID7Workflow .run ,
3972+ id = f"workflow-{ uuid .uuid4 ()} " ,
3973+ task_queue = task_queue ,
3974+ )
3975+ await handle2 .result ()
3976+ handle2_query_result = await handle2 .query (UUID7Workflow .result )
3977+
3978+ # Confirm they aren't equal to each other but they are equal to retries
3979+ # of the same query
3980+ assert handle1_query_result != handle2_query_result
3981+ assert handle1_query_result == await handle1 .query (UUID7Workflow .result )
3982+ assert handle2_query_result == await handle2 .query (UUID7Workflow .result )
3983+
3984+ # Confirm RFC 9562 shape: version 7, RFC variant, and the leading 48
3985+ # bits are the workflow time in milliseconds at generation
3986+ for handle , query_result in (
3987+ (handle1 , handle1_query_result ),
3988+ (handle2 , handle2_query_result ),
3989+ ):
3990+ result_uuid = uuid .UUID (query_result )
3991+ assert result_uuid .version == 7
3992+ assert result_uuid .variant == uuid .RFC_4122
3993+ workflow_time_ms = await handle .query (UUID7Workflow .time_ms )
3994+ assert int (result_uuid ) >> 80 == workflow_time_ms
3995+
3996+ # Now confirm those results are the same even on a new worker
3997+ async with new_worker (
3998+ client , UUID7Workflow , task_queue = task_queue , max_cached_workflows = 0
3999+ ):
4000+ assert handle1_query_result == await handle1 .query (UUID7Workflow .result )
4001+ assert handle2_query_result == await handle2 .query (UUID7Workflow .result )
4002+
4003+
39374004@activity .defn (name = "custom-name" )
39384005class CallableClassActivity :
39394006 def __init__ (self , orig_field1 : str ) -> None :
0 commit comments