@@ -80,39 +80,58 @@ describe('Worker choice strategies context test suite', () => {
8080 expect ( workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ) . toBe (
8181 WorkerChoiceStrategies . ROUND_ROBIN ,
8282 )
83- const workerChoiceStrategyUndefinedStub =
84- new RoundRobinWorkerChoiceStrategy ( fixedPool )
83+ const workerChoiceStrategyUndefinedStub = workerChoiceStrategiesContext
84+ . workerChoiceStrategies . get (
85+ workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ,
86+ )
8587 stub (
8688 workerChoiceStrategyUndefinedStub ,
8789 'choose' ,
8890 returnsNext ( Array ( 7 ) . fill ( undefined ) ) ,
8991 )
90- workerChoiceStrategiesContext . workerChoiceStrategies . set (
91- workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ,
92- workerChoiceStrategyUndefinedStub ,
92+ let err
93+ try {
94+ workerChoiceStrategiesContext . execute ( )
95+ } catch ( e ) {
96+ err = e
97+ }
98+ expect ( err ) . toBeInstanceOf ( Error )
99+ expect ( err . message ) . toBe (
100+ `Worker node key chosen by ${ workerChoiceStrategyUndefinedStub . name } is null or undefined after ${ workerChoiceStrategyUndefinedStub . retriesCount . toString ( ) } retries (max: ${ workerChoiceStrategiesContext . retries . toString ( ) } )` ,
93101 )
94- expect ( ( ) => workerChoiceStrategiesContext . execute ( ) ) . toThrow (
95- new Error (
96- `Worker node key chosen by ${ workerChoiceStrategyUndefinedStub . name } is null or undefined after ${ workerChoiceStrategiesContext . retries . toString ( ) } retries (max: ${ workerChoiceStrategiesContext . retries . toString ( ) } )` ,
97- ) ,
102+ assertSpyCalls (
103+ workerChoiceStrategyUndefinedStub . choose ,
104+ workerChoiceStrategyUndefinedStub . retriesCount + 1 ,
98105 )
99- workerChoiceStrategyUndefinedStub . choose . restore ( )
100- const workerChoiceStrategyNullStub = new RoundRobinWorkerChoiceStrategy (
101- fixedPool ,
106+ expect ( workerChoiceStrategiesContext . getStrategyRetries ( ) ) . toBe (
107+ workerChoiceStrategyUndefinedStub . retriesCount ,
102108 )
109+ workerChoiceStrategyUndefinedStub . choose . restore ( )
110+ const workerChoiceStrategyNullStub = workerChoiceStrategiesContext
111+ . workerChoiceStrategies . get (
112+ workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ,
113+ )
103114 stub (
104115 workerChoiceStrategyNullStub ,
105116 'choose' ,
106117 returnsNext ( Array ( 7 ) . fill ( null ) ) ,
107118 )
108- workerChoiceStrategiesContext . workerChoiceStrategies . set (
109- workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ,
110- workerChoiceStrategyNullStub ,
119+ err = undefined
120+ try {
121+ workerChoiceStrategiesContext . execute ( )
122+ } catch ( e ) {
123+ err = e
124+ }
125+ expect ( err ) . toBeInstanceOf ( Error )
126+ expect ( err . message ) . toBe (
127+ `Worker node key chosen by ${ workerChoiceStrategyNullStub . name } is null or undefined after ${ workerChoiceStrategyNullStub . retriesCount . toString ( ) } retries (max: ${ workerChoiceStrategiesContext . retries . toString ( ) } )` ,
111128 )
112- expect ( ( ) => workerChoiceStrategiesContext . execute ( ) ) . toThrow (
113- new Error (
114- `Worker node key chosen by ${ workerChoiceStrategyNullStub . name } is null or undefined after ${ workerChoiceStrategiesContext . retries . toString ( ) } retries (max: ${ workerChoiceStrategiesContext . retries . toString ( ) } )` ,
115- ) ,
129+ assertSpyCalls (
130+ workerChoiceStrategyNullStub . choose ,
131+ workerChoiceStrategyUndefinedStub . retriesCount + 1 ,
132+ )
133+ expect ( workerChoiceStrategiesContext . getStrategyRetries ( ) ) . toBe (
134+ workerChoiceStrategyNullStub . retriesCount ,
116135 )
117136 workerChoiceStrategyNullStub . choose . restore ( )
118137 } )
@@ -121,28 +140,21 @@ describe('Worker choice strategies context test suite', () => {
121140 const workerChoiceStrategiesContext = new WorkerChoiceStrategiesContext (
122141 fixedPool ,
123142 )
124- const workerChoiceStrategyStub = new RoundRobinWorkerChoiceStrategy (
125- fixedPool ,
143+ expect ( workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ) . toBe (
144+ WorkerChoiceStrategies . ROUND_ROBIN ,
126145 )
146+ const workerChoiceStrategyStub = workerChoiceStrategiesContext
147+ . workerChoiceStrategies . get (
148+ workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ,
149+ )
127150 stub (
128151 workerChoiceStrategyStub ,
129152 'choose' ,
130153 returnsNext ( Array ( 5 ) . fill ( undefined ) . concat ( Array ( 1 ) . fill ( 1 ) ) ) ,
131154 )
132- expect ( workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ) . toBe (
133- WorkerChoiceStrategies . ROUND_ROBIN ,
134- )
135- workerChoiceStrategiesContext . workerChoiceStrategies . set (
136- workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ,
137- workerChoiceStrategyStub ,
138- )
139155 const chosenWorkerKey = workerChoiceStrategiesContext . execute ( )
140- assertSpyCalls (
141- workerChoiceStrategiesContext . workerChoiceStrategies . get (
142- workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ,
143- ) . choose ,
144- 6 ,
145- )
156+ assertSpyCalls ( workerChoiceStrategyStub . choose , 6 )
157+ expect ( workerChoiceStrategiesContext . getStrategyRetries ( ) ) . toBe ( 5 )
146158 expect ( chosenWorkerKey ) . toBe ( 1 )
147159 workerChoiceStrategyStub . choose . restore ( )
148160 } )
@@ -151,24 +163,17 @@ describe('Worker choice strategies context test suite', () => {
151163 const workerChoiceStrategiesContext = new WorkerChoiceStrategiesContext (
152164 fixedPool ,
153165 )
154- const workerChoiceStrategyStub = new RoundRobinWorkerChoiceStrategy (
155- fixedPool ,
156- )
157- stub ( workerChoiceStrategyStub , 'choose' , returnsNext ( [ 0 ] ) )
158166 expect ( workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ) . toBe (
159167 WorkerChoiceStrategies . ROUND_ROBIN ,
160168 )
161- workerChoiceStrategiesContext . workerChoiceStrategies . set (
162- workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ,
163- workerChoiceStrategyStub ,
164- )
165- const chosenWorkerKey = workerChoiceStrategiesContext . execute ( )
166- assertSpyCalls (
167- workerChoiceStrategiesContext . workerChoiceStrategies . get (
169+ const workerChoiceStrategyStub = workerChoiceStrategiesContext
170+ . workerChoiceStrategies . get (
168171 workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ,
169- ) . choose ,
170- 1 ,
171- )
172+ )
173+ stub ( workerChoiceStrategyStub , 'choose' , returnsNext ( [ 0 ] ) )
174+ const chosenWorkerKey = workerChoiceStrategiesContext . execute ( )
175+ assertSpyCalls ( workerChoiceStrategyStub . choose , 1 )
176+ expect ( workerChoiceStrategiesContext . getStrategyRetries ( ) ) . toBe ( 0 )
172177 expect ( chosenWorkerKey ) . toBe ( 0 )
173178 workerChoiceStrategyStub . choose . restore ( )
174179 } )
@@ -177,24 +182,17 @@ describe('Worker choice strategies context test suite', () => {
177182 const workerChoiceStrategiesContext = new WorkerChoiceStrategiesContext (
178183 dynamicPool ,
179184 )
180- const workerChoiceStrategyStub = new RoundRobinWorkerChoiceStrategy (
181- dynamicPool ,
182- )
183- stub ( workerChoiceStrategyStub , 'choose' , returnsNext ( [ 0 ] ) )
184185 expect ( workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ) . toBe (
185186 WorkerChoiceStrategies . ROUND_ROBIN ,
186187 )
187- workerChoiceStrategiesContext . workerChoiceStrategies . set (
188- workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ,
189- workerChoiceStrategyStub ,
190- )
191- const chosenWorkerKey = workerChoiceStrategiesContext . execute ( )
192- assertSpyCalls (
193- workerChoiceStrategiesContext . workerChoiceStrategies . get (
188+ const workerChoiceStrategyStub = workerChoiceStrategiesContext
189+ . workerChoiceStrategies . get (
194190 workerChoiceStrategiesContext . defaultWorkerChoiceStrategy ,
195- ) . choose ,
196- 1 ,
197- )
191+ )
192+ stub ( workerChoiceStrategyStub , 'choose' , returnsNext ( [ 0 ] ) )
193+ const chosenWorkerKey = workerChoiceStrategiesContext . execute ( )
194+ assertSpyCalls ( workerChoiceStrategyStub . choose , 1 )
195+ expect ( workerChoiceStrategiesContext . getStrategyRetries ( ) ) . toBe ( 0 )
198196 expect ( chosenWorkerKey ) . toBe ( 0 )
199197 workerChoiceStrategyStub . choose . restore ( )
200198 } )
0 commit comments