19
19
20
20
namespace Google \Cloud \Samples \Functions \TipsRetry \Test ;
21
21
22
- use Google \Cloud \Logging \LoggingClient ;
23
22
use Google \Cloud \TestUtils \CloudFunctionDeploymentTrait ;
24
23
use Google \Cloud \PubSub \PubSubClient ;
25
24
use PHPUnit \Framework \TestCase ;
@@ -39,24 +38,14 @@ class DeployTest extends TestCase
39
38
40
39
private static $ entryPoint = 'tipsRetry ' ;
41
40
42
- /* var string */
43
- private static $ projectId ;
44
-
45
41
/* var string */
46
42
private static $ topicName ;
47
43
48
- /** @var LoggingClient */
49
- private static $ loggingClient ;
50
-
51
44
public function testTipsRetry (): void
52
45
{
53
46
// Send Pub/Sub message.
54
47
$ this ->publishMessage ();
55
48
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
-
60
49
$ fiveMinAgo = date (\DateTime::RFC3339 , strtotime ('-5 minutes ' ));
61
50
$ this ->processFunctionLogs ($ fiveMinAgo , function (\Iterator $ logs ) {
62
51
// Concatenate all relevant log messages.
@@ -67,7 +56,8 @@ public function testTipsRetry(): void
67
56
}
68
57
69
58
// 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 );
71
61
$ this ->assertGreaterThan (1 , $ retryCount );
72
62
});
73
63
}
@@ -90,14 +80,16 @@ private function publishMessage(): void
90
80
*/
91
81
private static function doDeploy ()
92
82
{
93
- self ::$ projectId = self ::requireEnv ('GOOGLE_CLOUD_PROJECT ' );
94
83
self ::$ topicName = self ::requireEnv ('FUNCTIONS_TOPIC ' );
95
84
96
85
/**
97
86
* The --retry flag tells Cloud Functions to automatically retry
98
87
* failed function invocations. This is necessary because we're
99
88
* the parent sample exists to demonstrate automatic retries.
100
89
*/
101
- return self ::$ fn ->deploy (['--retry ' => '' ], '--trigger-topic= ' . self ::$ topicName );
90
+ return self ::$ fn ->deploy (
91
+ ['--retry ' => '' ],
92
+ '--trigger-topic= ' . self ::$ topicName
93
+ );
102
94
}
103
95
}
0 commit comments