66
77use DateTime ;
88use DateTimeInterface ;
9+ use Keboola \StorageApi \Client ;
910use Keboola \StorageApi \ClientException ;
1011use Keboola \StorageApi \Workspaces ;
1112use Keboola \Test \Backend \Workspaces \Backend \WorkspaceBackendFactory ;
1213use Keboola \Test \StorageApiTestCase ;
14+ use Retry \BackOff \FixedBackOffPolicy ;
15+ use Retry \Policy \SimpleRetryPolicy ;
16+ use Retry \RetryProxy ;
1317
1418class ScheduledTasksTest extends StorageApiTestCase
1519{
@@ -176,10 +180,10 @@ public function testSchedulerWorker(): void
176180 // Schedule external bucket refresh task
177181 $ task = $ this ->_client ->scheduleBucketRefresh ($ bucketId , '* * * * * ' );
178182
179- sleep (120 ); // Wait for the Scheduler restart (every 60 seconds)
183+ sleep (60 ); // Wait for the Scheduler reload tasks from the database
180184
181185 // Check: Table created in workspace is after auto-refresh available in bucket
182- $ tablesAfterAutoRefresh = $ this ->_client -> listTables ( $ bucketId );
186+ $ tablesAfterAutoRefresh = $ this ->listTablesWithRetry ( $ this -> _client , $ bucketId );
183187 $ this ->assertCount (1 , $ tablesAfterAutoRefresh );
184188 $ this ->assertSame ('TO-AUTO-REFRESH ' , $ tablesAfterAutoRefresh [0 ]['name ' ]);
185189
@@ -189,7 +193,7 @@ public function testSchedulerWorker(): void
189193 // Create another table in workspace
190194 $ db ->createTable ('TO-MANUAL-REFRESH ' , ['ID ' => 'NUMBER ' , 'NAME ' => 'TEXT ' ]);
191195
192- sleep (120 ); // Wait for the Scheduler restart
196+ sleep (90 ); // Wait for the Scheduler restart
193197
194198 // Check: Second table created in workspace is not available in bucket because of stopped auto-refresh
195199 $ tablesOutdated = $ this ->_client ->listTables ($ bucketId );
@@ -203,4 +207,23 @@ public function testSchedulerWorker(): void
203207 $ this ->assertSame ('TO-AUTO-REFRESH ' , $ tablesAfterManualRefresh [0 ]['name ' ]);
204208 $ this ->assertSame ('TO-MANUAL-REFRESH ' , $ tablesAfterManualRefresh [1 ]['name ' ]);
205209 }
210+
211+ private function listTablesWithRetry (Client $ client , string $ bucketId ): array
212+ {
213+ $ proxy = new RetryProxy (
214+ new SimpleRetryPolicy (10 ),
215+ new FixedBackOffPolicy (6000 ),
216+ );
217+
218+ /** @var array $tables */
219+ $ tables = $ proxy ->call (function () use ($ client , $ bucketId ): array {
220+ $ tables = $ client ->listTables ($ bucketId );
221+
222+ $ this ->assertNotEmpty ($ tables , 'There must be at least one table in the bucket. ' );
223+
224+ return $ tables ;
225+ });
226+
227+ return $ tables ;
228+ }
206229}
0 commit comments