@@ -97,7 +97,11 @@ public function testStandaloneQueryPollAndCompleteUseCachedLease(): void
9797 });
9898
9999 $ client = new WorkerProtocolClient ($ http , 'http://server:8080 ' , 'test-token ' , 'default ' );
100- $ tasks = $ client ->pollQueryTasks (queue: 'polyglot ' , workerId: 'php-worker ' );
100+ $ tasks = $ client ->pollQueryTasks (
101+ queue: 'polyglot ' ,
102+ workerId: 'php-worker ' ,
103+ pollRequestId: 'query-poll-request-1 ' ,
104+ );
101105 $ complete = $ client ->completeQueryTask ('query-task-1 ' , 'waiting ' , [
102106 'codec ' => 'avro ' ,
103107 'blob ' => 'encoded-result ' ,
@@ -110,7 +114,11 @@ public function testStandaloneQueryPollAndCompleteUseCachedLease(): void
110114 [
111115 'method ' => 'POST ' ,
112116 'url ' => 'http://server:8080/api/worker/query-tasks/poll ' ,
113- 'body ' => ['worker_id ' => 'php-worker ' , 'task_queue ' => 'polyglot ' ],
117+ 'body ' => [
118+ 'worker_id ' => 'php-worker ' ,
119+ 'task_queue ' => 'polyglot ' ,
120+ 'poll_request_id ' => 'query-poll-request-1 ' ,
121+ ],
114122 ],
115123 [
116124 'method ' => 'POST ' ,
@@ -154,7 +162,11 @@ public function testStandaloneQueryFailureUsesCachedLease(): void
154162 });
155163
156164 $ client = new WorkerProtocolClient ($ http , 'http://server:8080 ' , 'test-token ' , 'default ' );
157- $ client ->pollQueryTasks (queue: 'polyglot ' , workerId: 'php-worker ' );
165+ $ client ->pollQueryTasks (
166+ queue: 'polyglot ' ,
167+ workerId: 'php-worker ' ,
168+ pollRequestId: 'query-poll-request-2 ' ,
169+ );
158170 $ failure = $ client ->failQueryTask (
159171 'query-task-1 ' ,
160172 'No query handler. ' ,
@@ -170,7 +182,11 @@ public function testStandaloneQueryFailureUsesCachedLease(): void
170182 [
171183 'method ' => 'POST ' ,
172184 'url ' => 'http://server:8080/api/worker/query-tasks/poll ' ,
173- 'body ' => ['worker_id ' => 'php-worker ' , 'task_queue ' => 'polyglot ' ],
185+ 'body ' => [
186+ 'worker_id ' => 'php-worker ' ,
187+ 'task_queue ' => 'polyglot ' ,
188+ 'poll_request_id ' => 'query-poll-request-2 ' ,
189+ ],
174190 ],
175191 [
176192 'method ' => 'POST ' ,
@@ -191,6 +207,40 @@ public function testStandaloneQueryFailureUsesCachedLease(): void
191207 ], $ requests );
192208 }
193209
210+ public function testStandaloneQueryPollRetriesTimeoutWithSamePollRequestId (): void
211+ {
212+ $ http = new HttpFactory ();
213+ $ requests = [];
214+
215+ $ http ->fake (function (Request $ request ) use ($ http , &$ requests ) {
216+ $ requests [] = $ request ->data ();
217+
218+ if (count ($ requests ) === 1 ) {
219+ throw new ConnectionException ('cURL error 28: Operation timed out ' );
220+ }
221+
222+ return $ http ->response ([
223+ 'task ' => [
224+ 'query_task_id ' => 'query-task-retry ' ,
225+ 'query_task_attempt ' => 1 ,
226+ 'lease_owner ' => 'php-worker ' ,
227+ ],
228+ ]);
229+ });
230+
231+ $ client = new WorkerProtocolClient ($ http , 'http://server:8080 ' , 'test-token ' , 'default ' );
232+ $ tasks = $ client ->pollQueryTasks (queue: 'polyglot ' , workerId: 'php-worker ' );
233+
234+ $ this ->assertCount (1 , $ tasks );
235+ $ this ->assertSame ('query-task-retry ' , $ tasks [0 ]['query_task_id ' ]);
236+ $ this ->assertCount (2 , $ requests );
237+ $ this ->assertSame ('php-worker ' , $ requests [0 ]['worker_id ' ]);
238+ $ this ->assertSame ('polyglot ' , $ requests [0 ]['task_queue ' ]);
239+ $ this ->assertIsString ($ requests [0 ]['poll_request_id ' ]);
240+ $ this ->assertNotSame ('' , $ requests [0 ]['poll_request_id ' ]);
241+ $ this ->assertSame ($ requests [0 ]['poll_request_id ' ], $ requests [1 ]['poll_request_id ' ]);
242+ }
243+
194244 public function testPollWorkflowTasksUsesStandaloneWorkerApiByDefault (): void
195245 {
196246 $ http = new HttpFactory ();
0 commit comments