1- use temporalio_common:: worker:: { WorkerConfigBuilder , WorkerTaskTypes , WorkerVersioningStrategy } ;
1+ use std:: collections:: HashSet ;
2+ use temporalio_common:: worker:: {
3+ WorkerConfigBuilder , WorkerTaskType , WorkerTaskTypes , WorkerVersioningStrategy ,
4+ worker_task_types,
5+ } ;
26
37fn default_versioning_strategy ( ) -> WorkerVersioningStrategy {
48 WorkerVersioningStrategy :: None {
@@ -15,16 +19,19 @@ fn test_default_configuration_polls_all_types() {
1519 . build ( )
1620 . expect ( "Failed to build default config" ) ;
1721
18- let effective = config. task_types ;
22+ let effective = & config. task_types ;
1923 assert ! (
20- effective. polls_workflows ( ) ,
24+ effective. contains ( & WorkerTaskType :: Workflows ) ,
2125 "Should poll workflows by default"
2226 ) ;
2327 assert ! (
24- effective. polls_activities ( ) ,
28+ effective. contains ( & WorkerTaskType :: Activities ) ,
2529 "Should poll activities by default"
2630 ) ;
27- assert ! ( effective. polls_nexus( ) , "Should poll nexus by default" ) ;
31+ assert ! (
32+ effective. contains( & WorkerTaskType :: Nexus ) ,
33+ "Should poll nexus by default"
34+ ) ;
2835}
2936
3037#[ test]
@@ -33,32 +40,53 @@ fn test_workflow_only_worker() {
3340 . namespace ( "default" )
3441 . task_queue ( "test-queue" )
3542 . versioning_strategy ( default_versioning_strategy ( ) )
36- . task_types ( WorkerTaskTypes :: WORKFLOWS )
43+ . task_types ( HashSet :: from ( [ WorkerTaskType :: Workflows ] ) )
3744 . max_cached_workflows ( 0usize )
3845 . build ( )
3946 . expect ( "Failed to build workflow-only config" ) ;
4047
41- let effective = config. task_types ;
42- assert ! ( effective. polls_workflows( ) , "Should poll workflows" ) ;
43- assert ! ( !effective. polls_activities( ) , "Should NOT poll activities" ) ;
44- assert ! ( !effective. polls_nexus( ) , "Should NOT poll nexus" ) ;
48+ let effective = & config. task_types ;
49+ assert ! (
50+ effective. contains( & WorkerTaskType :: Workflows ) ,
51+ "Should poll workflows"
52+ ) ;
53+ assert ! (
54+ !effective. contains( & WorkerTaskType :: Activities ) ,
55+ "Should NOT poll activities"
56+ ) ;
57+ assert ! (
58+ !effective. contains( & WorkerTaskType :: Nexus ) ,
59+ "Should NOT poll nexus"
60+ ) ;
4561}
4662
4763#[ test]
4864fn test_activity_and_nexus_worker ( ) {
65+ let types: WorkerTaskTypes = [ WorkerTaskType :: Activities , WorkerTaskType :: Nexus ]
66+ . into_iter ( )
67+ . collect ( ) ;
4968 let config = WorkerConfigBuilder :: default ( )
5069 . namespace ( "default" )
5170 . task_queue ( "test-queue" )
5271 . versioning_strategy ( default_versioning_strategy ( ) )
53- . task_types ( WorkerTaskTypes :: ACTIVITIES | WorkerTaskTypes :: NEXUS )
72+ . task_types ( types )
5473 . max_cached_workflows ( 0usize )
5574 . build ( )
5675 . expect ( "Failed to build activity+nexus config" ) ;
5776
58- let effective = config. task_types ;
59- assert ! ( !effective. polls_workflows( ) , "Should NOT poll workflows" ) ;
60- assert ! ( effective. polls_activities( ) , "Should poll activities" ) ;
61- assert ! ( effective. polls_nexus( ) , "Should poll nexus" ) ;
77+ let effective = & config. task_types ;
78+ assert ! (
79+ !effective. contains( & WorkerTaskType :: Workflows ) ,
80+ "Should NOT poll workflows"
81+ ) ;
82+ assert ! (
83+ effective. contains( & WorkerTaskType :: Activities ) ,
84+ "Should poll activities"
85+ ) ;
86+ assert ! (
87+ effective. contains( & WorkerTaskType :: Nexus ) ,
88+ "Should poll nexus"
89+ ) ;
6290}
6391
6492#[ test]
@@ -67,7 +95,7 @@ fn test_empty_task_types_fails_validation() {
6795 . namespace ( "default" )
6896 . task_queue ( "test-queue" )
6997 . versioning_strategy ( default_versioning_strategy ( ) )
70- . task_types ( WorkerTaskTypes :: empty ( ) )
98+ . task_types ( WorkerTaskTypes :: new ( ) )
7199 . build ( ) ;
72100
73101 assert ! ( result. is_err( ) , "Empty task_types should fail validation" ) ;
@@ -84,7 +112,7 @@ fn test_workflow_cache_without_workflows_fails() {
84112 . namespace ( "default" )
85113 . task_queue ( "test-queue" )
86114 . versioning_strategy ( default_versioning_strategy ( ) )
87- . task_types ( WorkerTaskTypes :: ACTIVITIES )
115+ . task_types ( worker_task_types :: activities ( ) )
88116 . max_cached_workflows ( 10usize )
89117 . build ( ) ;
90118
@@ -102,30 +130,36 @@ fn test_workflow_cache_without_workflows_fails() {
102130#[ test]
103131fn test_all_combinations ( ) {
104132 let combinations = [
105- ( WorkerTaskTypes :: WORKFLOWS , "workflows only" ) ,
106- ( WorkerTaskTypes :: ACTIVITIES , "activities only" ) ,
107- ( WorkerTaskTypes :: NEXUS , "nexus only" ) ,
133+ ( worker_task_types :: workflows ( ) , "workflows only" ) ,
134+ ( worker_task_types :: activities ( ) , "activities only" ) ,
135+ ( worker_task_types :: nexus ( ) , "nexus only" ) ,
108136 (
109- WorkerTaskTypes :: WORKFLOWS | WorkerTaskTypes :: ACTIVITIES ,
137+ [ WorkerTaskType :: Workflows , WorkerTaskType :: Activities ]
138+ . into_iter ( )
139+ . collect ( ) ,
110140 "workflows + activities" ,
111141 ) ,
112142 (
113- WorkerTaskTypes :: WORKFLOWS | WorkerTaskTypes :: NEXUS ,
143+ [ WorkerTaskType :: Workflows , WorkerTaskType :: Nexus ]
144+ . into_iter ( )
145+ . collect ( ) ,
114146 "workflows + nexus" ,
115147 ) ,
116148 (
117- WorkerTaskTypes :: ACTIVITIES | WorkerTaskTypes :: NEXUS ,
149+ [ WorkerTaskType :: Activities , WorkerTaskType :: Nexus ]
150+ . into_iter ( )
151+ . collect ( ) ,
118152 "activities + nexus" ,
119153 ) ,
120- ( WorkerTaskTypes :: all ( ) , "all types" ) ,
154+ ( worker_task_types :: all ( ) , "all types" ) ,
121155 ] ;
122156
123157 for ( task_types, description) in combinations {
124158 let config = WorkerConfigBuilder :: default ( )
125159 . namespace ( "default" )
126160 . task_queue ( "test-queue" )
127161 . versioning_strategy ( default_versioning_strategy ( ) )
128- . task_types ( task_types)
162+ . task_types ( task_types. clone ( ) )
129163 . build ( )
130164 . unwrap_or_else ( |e| panic ! ( "Failed to build config for {description}: {e:?}" ) ) ;
131165
0 commit comments