From e3a917752a85488e4d5c2843700a8a3f177cf09b Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 12 Apr 2021 10:18:00 -0700 Subject: [PATCH 1/4] fix helloworld pubsub sample --- functions/helloworld_pubsub/index.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/functions/helloworld_pubsub/index.php b/functions/helloworld_pubsub/index.php index 16a82da024..bd2f64f18b 100644 --- a/functions/helloworld_pubsub/index.php +++ b/functions/helloworld_pubsub/index.php @@ -24,8 +24,10 @@ function helloworldPubsub(CloudEvent $event): void $log = fopen(getenv('LOGGER_OUTPUT') ?: 'php://stderr', 'wb'); $cloudEventData = $event->getData(); - if (isset($cloudEventData['data'])) { - $name = htmlspecialchars(base64_decode($cloudEventData['data'])); + $pubSubData = $cloudEventData['message']['data']; + + if ($pubSubData) { + $name = htmlspecialchars(base64_decode($pubSubData)); } else { $name = 'World'; } From 22d51827fdc39a94465baba6fb20043c45044837 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 12 Apr 2021 10:32:53 -0700 Subject: [PATCH 2/4] Update DeployTest.php --- functions/helloworld_pubsub/test/DeployTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/functions/helloworld_pubsub/test/DeployTest.php b/functions/helloworld_pubsub/test/DeployTest.php index fdea505e47..3214a967e7 100644 --- a/functions/helloworld_pubsub/test/DeployTest.php +++ b/functions/helloworld_pubsub/test/DeployTest.php @@ -72,10 +72,6 @@ public function testHelloworldPubsub(string $name, string $expected, string $lab // Send Pub/Sub message. $this->publishMessage($name); - // Give event and log systems a head start. - // If log retrieval fails to find logs for our function within retry limit, increase sleep time. - sleep(60); - $fiveMinAgo = date(\DateTime::RFC3339, strtotime('-5 minutes')); $this->processFunctionLogs($fiveMinAgo, function (\Iterator $logs) use ($name, $expected, $label) { // Concatenate all relevant log messages. From 62cf46a143536e8dc157b2494127d29a4c7be5cd Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 12 Apr 2021 10:39:37 -0700 Subject: [PATCH 3/4] Update index.php --- functions/helloworld_pubsub/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/helloworld_pubsub/index.php b/functions/helloworld_pubsub/index.php index bd2f64f18b..8794579b8b 100644 --- a/functions/helloworld_pubsub/index.php +++ b/functions/helloworld_pubsub/index.php @@ -24,10 +24,10 @@ function helloworldPubsub(CloudEvent $event): void $log = fopen(getenv('LOGGER_OUTPUT') ?: 'php://stderr', 'wb'); $cloudEventData = $event->getData(); - $pubSubData = $cloudEventData['message']['data']; + $pubSubData = base64_decode($cloudEventData['message']['data']); if ($pubSubData) { - $name = htmlspecialchars(base64_decode($pubSubData)); + $name = htmlspecialchars($pubSubData); } else { $name = 'World'; } From 537c5810d9cc1e9d0d43c6da1fd478c3583d34ce Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 12 Apr 2021 17:49:05 -0700 Subject: [PATCH 4/4] fix integration test --- functions/helloworld_pubsub/test/IntegrationTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/functions/helloworld_pubsub/test/IntegrationTest.php b/functions/helloworld_pubsub/test/IntegrationTest.php index 0624ea7ca2..2e351c8c2f 100644 --- a/functions/helloworld_pubsub/test/IntegrationTest.php +++ b/functions/helloworld_pubsub/test/IntegrationTest.php @@ -60,7 +60,9 @@ public function dataProvider() 'type' => 'google.cloud.pubsub.topic.v1.messagePublished', ], 'data' => [ - 'data' => base64_encode('John') + 'message' => [ + 'data' => base64_encode('John') + ] ], 'statusCode' => 200, 'expected' => 'Hello, John!',