Skip to content

Commit 6364b34

Browse files
authored
fix: helloworld pubsub sample (GoogleCloudPlatform#1340)
- Fixes how pubsub message data is handled in the sample - Removes `sleep` from test, since this is handled by retrying in `processFunctionsLogs`
1 parent 3ea96ab commit 6364b34

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

functions/helloworld_pubsub/index.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ function helloworldPubsub(CloudEvent $event): void
2424
$log = fopen(getenv('LOGGER_OUTPUT') ?: 'php://stderr', 'wb');
2525

2626
$cloudEventData = $event->getData();
27-
if (isset($cloudEventData['data'])) {
28-
$name = htmlspecialchars(base64_decode($cloudEventData['data']));
27+
$pubSubData = base64_decode($cloudEventData['message']['data']);
28+
29+
if ($pubSubData) {
30+
$name = htmlspecialchars($pubSubData);
2931
} else {
3032
$name = 'World';
3133
}

functions/helloworld_pubsub/test/DeployTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ public function testHelloworldPubsub(string $name, string $expected, string $lab
7272
// Send Pub/Sub message.
7373
$this->publishMessage($name);
7474

75-
// Give event and log systems a head start.
76-
// If log retrieval fails to find logs for our function within retry limit, increase sleep time.
77-
sleep(60);
78-
7975
$fiveMinAgo = date(\DateTime::RFC3339, strtotime('-5 minutes'));
8076
$this->processFunctionLogs($fiveMinAgo, function (\Iterator $logs) use ($name, $expected, $label) {
8177
// Concatenate all relevant log messages.

functions/helloworld_pubsub/test/IntegrationTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ public function dataProvider()
6060
'type' => 'google.cloud.pubsub.topic.v1.messagePublished',
6161
],
6262
'data' => [
63-
'data' => base64_encode('John')
63+
'message' => [
64+
'data' => base64_encode('John')
65+
]
6466
],
6567
'statusCode' => 200,
6668
'expected' => 'Hello, John!',

0 commit comments

Comments
 (0)