1919
2020namespace Google \Cloud \Samples \Functions \TipsRetry \Test ;
2121
22- use Google \Cloud \Logging \LoggingClient ;
2322use Google \Cloud \TestUtils \CloudFunctionDeploymentTrait ;
2423use Google \Cloud \PubSub \PubSubClient ;
2524use PHPUnit \Framework \TestCase ;
@@ -39,24 +38,14 @@ class DeployTest extends TestCase
3938
4039 private static $ entryPoint = 'tipsRetry ' ;
4140
42- /* var string */
43- private static $ projectId ;
44-
4541 /* var string */
4642 private static $ topicName ;
4743
48- /** @var LoggingClient */
49- private static $ loggingClient ;
50-
5144 public function testTipsRetry (): void
5245 {
5346 // Send Pub/Sub message.
5447 $ this ->publishMessage ();
5548
56- // Give event and log systems a head start.
57- // If log retrieval fails to find logs for our function within retry limit, increase sleep time.
58- sleep (60 );
59-
6049 $ fiveMinAgo = date (\DateTime::RFC3339 , strtotime ('-5 minutes ' ));
6150 $ this ->processFunctionLogs ($ fiveMinAgo , function (\Iterator $ logs ) {
6251 // Concatenate all relevant log messages.
@@ -67,7 +56,8 @@ public function testTipsRetry(): void
6756 }
6857
6958 // Check that multiple invocations of the function have occurred.
70- $ retryCount = substr_count ($ actual , 'Retrying... ' );
59+ $ retryText = 'Intermittent failure occurred; retrying... ' ;
60+ $ retryCount = substr_count ($ actual , $ retryText );
7161 $ this ->assertGreaterThan (1 , $ retryCount );
7262 });
7363 }
@@ -90,14 +80,16 @@ private function publishMessage(): void
9080 */
9181 private static function doDeploy ()
9282 {
93- self ::$ projectId = self ::requireEnv ('GOOGLE_CLOUD_PROJECT ' );
9483 self ::$ topicName = self ::requireEnv ('FUNCTIONS_TOPIC ' );
9584
9685 /**
9786 * The --retry flag tells Cloud Functions to automatically retry
9887 * failed function invocations. This is necessary because we're
9988 * the parent sample exists to demonstrate automatic retries.
10089 */
101- return self ::$ fn ->deploy (['--retry ' => '' ], '--trigger-topic= ' . self ::$ topicName );
90+ return self ::$ fn ->deploy (
91+ ['--retry ' => '' ],
92+ '--trigger-topic= ' . self ::$ topicName
93+ );
10294 }
10395}
0 commit comments