Skip to content

Commit d694e60

Browse files
authored
eventual consistency fix for monitoring tests (GoogleCloudPlatform#413)
1 parent 4cd4703 commit d694e60

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

monitoring/test/monitoringTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public function testCreateMetric()
4646
$this->assertContains(self::$metricId, $output);
4747

4848
// ensure the metric gets created
49-
$this->eventuallyConsistentRetryCount = 20;
5049
$this->runEventuallyConsistentTest(function () {
5150
$output = $this->runCommand('get-descriptor', [
5251
'metric_id' => self::$metricId,
@@ -64,14 +63,14 @@ public function testGetDescriptor()
6463
$this->assertContains(self::$metricId, $output);
6564
}
6665

67-
/** @depends testCreateMetric */
66+
/** @depends testGetDescriptor */
6867
public function testListDescriptors()
6968
{
7069
$output = $this->runCommand('list-descriptors');
7170
$this->assertContains(self::$metricId, $output);
7271
}
7372

74-
/** @depends testCreateMetric */
73+
/** @depends testListDescriptors */
7574
public function testDeleteMetric()
7675
{
7776
$output = $this->runCommand('delete-metric', [
@@ -132,10 +131,15 @@ private function runCommand($commandName, $args = [])
132131
$commandTester = new CommandTester($command);
133132

134133
ob_start();
135-
$commandTester->execute(
136-
['project_id' => self::$projectId] + $args,
137-
['interactive' => false]);
138-
134+
try {
135+
$commandTester->execute(
136+
['project_id' => self::$projectId] + $args,
137+
['interactive' => false]);
138+
} catch (\Google\GAX\Exception $e) {
139+
// if the command throws an error cast it as a string (as this would be the output)
140+
$application->renderException($e, $commandTester->getOutput());
141+
return $commandTester->getDisplay();
142+
}
139143
return ob_get_clean();
140144
}
141145
}

0 commit comments

Comments
 (0)