Improve Test Reliabiltiy
This commit is contained in:
parent
a8b5a8a038
commit
e17f391f25
2 changed files with 66 additions and 36 deletions
|
@ -6,6 +6,7 @@ use Appwrite\Functions\Specification;
|
|||
use Appwrite\Tests\Retry;
|
||||
use CURLFile;
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
|
@ -894,37 +895,51 @@ class UsageTest extends Scope
|
|||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
|
||||
sleep(self::WAIT + 20);
|
||||
$tries = 0;
|
||||
|
||||
// Compare new values with old values
|
||||
$response = $this->client->call(
|
||||
Client::METHOD_GET,
|
||||
'/functions/' . $functionId . '/usage?range=30d',
|
||||
$this->getConsoleHeaders()
|
||||
);
|
||||
while (true) {
|
||||
try {
|
||||
// Compare new values with old values
|
||||
$response = $this->client->call(
|
||||
Client::METHOD_GET,
|
||||
'/functions/' . $functionId . '/usage?range=30d',
|
||||
$this->getConsoleHeaders()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals(19, count($response['body']));
|
||||
$this->assertEquals('30d', $response['body']['range']);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals(19, count($response['body']));
|
||||
$this->assertEquals('30d', $response['body']['range']);
|
||||
|
||||
// Check if the new values are greater than the old values
|
||||
$this->assertEquals($functionsMetrics['executionsTotal'] + 1, $response['body']['executionsTotal']);
|
||||
$this->assertGreaterThan($functionsMetrics['executionsTimeTotal'], $response['body']['executionsTimeTotal']);
|
||||
$this->assertGreaterThan($functionsMetrics['executionsMbSecondsTotal'], $response['body']['executionsMbSecondsTotal']);
|
||||
// Check if the new values are greater than the old values
|
||||
$this->assertEquals($functionsMetrics['executionsTotal'] + 1, $response['body']['executionsTotal']);
|
||||
$this->assertGreaterThan($functionsMetrics['executionsTimeTotal'], $response['body']['executionsTimeTotal']);
|
||||
$this->assertGreaterThan($functionsMetrics['executionsMbSecondsTotal'], $response['body']['executionsMbSecondsTotal']);
|
||||
|
||||
$response = $this->client->call(
|
||||
Client::METHOD_GET,
|
||||
'/project/usage',
|
||||
$this->getConsoleHeaders(),
|
||||
[
|
||||
'period' => '1h',
|
||||
'startDate' => self::getToday(),
|
||||
'endDate' => self::getTomorrow(),
|
||||
]
|
||||
);
|
||||
$response = $this->client->call(
|
||||
Client::METHOD_GET,
|
||||
'/project/usage',
|
||||
$this->getConsoleHeaders(),
|
||||
[
|
||||
'period' => '1h',
|
||||
'startDate' => self::getToday(),
|
||||
'endDate' => self::getTomorrow(),
|
||||
]
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals($projectMetrics['executionsTotal'] + 1, $response['body']['executionsTotal']);
|
||||
$this->assertGreaterThan($projectMetrics['executionsMbSecondsTotal'], $response['body']['executionsMbSecondsTotal']);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals($projectMetrics['executionsTotal'] + 1, $response['body']['executionsTotal']);
|
||||
$this->assertGreaterThan($projectMetrics['executionsMbSecondsTotal'], $response['body']['executionsMbSecondsTotal']);
|
||||
|
||||
break;
|
||||
} catch (ExpectationFailedException $th) {
|
||||
if ($tries >= 5) {
|
||||
throw $th;
|
||||
} else {
|
||||
$tries++;
|
||||
sleep(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Tests\E2E\Services\Functions;
|
|||
use Appwrite\Functions\Specification;
|
||||
use Appwrite\Tests\Retry;
|
||||
use CURLFile;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
|
@ -2435,17 +2436,31 @@ class FunctionsCustomServerTest extends Scope
|
|||
// Await Aggregation
|
||||
sleep(App::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', 30));
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/usage', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id']
|
||||
], $this->getHeaders()), [
|
||||
'range' => '24h'
|
||||
]);
|
||||
$tries = 0;
|
||||
while (true) {
|
||||
try {
|
||||
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/usage', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id']
|
||||
], $this->getHeaders()), [
|
||||
'range' => '24h'
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals(19, count($response['body']));
|
||||
$this->assertEquals('24h', $response['body']['range']);
|
||||
$this->assertEquals(1, $response['body']['executionsTotal']);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals(19, count($response['body']));
|
||||
$this->assertEquals('24h', $response['body']['range']);
|
||||
$this->assertEquals(1, $response['body']['executionsTotal']);
|
||||
|
||||
break;
|
||||
} catch (ExpectationFailedException $th) {
|
||||
if ($tries >= 5) {
|
||||
throw $th;
|
||||
} else {
|
||||
$tries++;
|
||||
sleep(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup : Delete function
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [
|
||||
|
|
Loading…
Reference in a new issue