1
0
Fork 0
mirror of synced 2024-06-27 02:31:04 +12:00

Fix retry build test

This commit is contained in:
Jake Barnby 2023-08-28 21:11:57 -04:00
parent 08ab9b016e
commit ef25c176ed
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
2 changed files with 61 additions and 30 deletions

View file

@ -1376,8 +1376,10 @@ trait Base
return 'query getDeployment($functionId: String!, $deploymentId: String!) {
functionsGetDeployment(functionId: $functionId, deploymentId: $deploymentId) {
_id
resourceId
buildId
buildLogs
status
}
}';
case self::$CREATE_FUNCTION:

View file

@ -105,26 +105,59 @@ class FunctionsServerTest extends Scope
$this->assertIsArray($deployment['body']['data']);
$this->assertArrayNotHasKey('errors', $deployment['body']);
sleep(15);
// Poll get deployment until an error, or status is either 'ready' or 'failed'
$deployment = $deployment['body']['data']['functionsCreateDeployment'];
$deploymentId = $deployment['_id'];
return $deployment['body']['data']['functionsCreateDeployment'];
$query = $this->getQuery(self::$GET_DEPLOYMENT);
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'deploymentId' => $deploymentId,
]
];
while (true) {
$deployment = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertIsArray($deployment['body']['data']);
$this->assertArrayNotHasKey('errors', $deployment['body']);
$deployment = $deployment['body']['data']['functionsGetDeployment'];
if (
$deployment['status'] === 'ready'
|| $deployment['status'] === 'failed'
) {
break;
}
\sleep(1);
}
$this->assertEquals('ready', $deployment['status']);
return $deployment;
}
/**
* * @depends testCreateFunction
* @depends testCreateDeployment
* @param $function
* @param $deployment
* @return array
* @throws \Exception
*/
public function testCreateExecution($function): array
public function testCreateExecution($deployment): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_EXECUTION);
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'functionId' => $deployment['resourceId'],
]
];
@ -133,6 +166,8 @@ class FunctionsServerTest extends Scope
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
\var_dump($execution);
$this->assertIsArray($execution['body']['data']);
$this->assertArrayNotHasKey('errors', $execution['body']);
@ -140,33 +175,31 @@ class FunctionsServerTest extends Scope
}
/**
* @depends testCreateFunction
* @depends testGetDeployment
* @param $function
* @param $deployment
* @return array
* @return void
* @throws \Exception
*/
public function testCreateRetryBuild($function, $deployment): void
public function testCreateRetryBuild($deployment): void
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$RETRY_BUILD);
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'functionId' => $deployment['resourceId'],
'deploymentId' => $deployment['_id'],
'buildId' => $deployment['buildId'],
]
];
$retryBuild = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
$response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertIsArray($retryBuild['body']['errors']);
$this->assertEquals("Build not failed", $retryBuild['body']['errors'][0]['message']);
$this->assertIsNotArray($response['body']);
$this->assertEquals(204, $response['headers']['status-code']);
}
public function testGetFunctions(): array
@ -272,20 +305,19 @@ class FunctionsServerTest extends Scope
}
/**
* @depends testCreateFunction
* @depends testCreateDeployment
* @param $function
* @param $deployment
* @return array
* @throws \Exception
*/
public function testGetDeployment($function, $deployment)
public function testGetDeployment($deployment)
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_DEPLOYMENT);
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'functionId' => $deployment['resourceId'],
'deploymentId' => $deployment['_id'],
]
];
@ -334,21 +366,19 @@ class FunctionsServerTest extends Scope
}
/**
* @depends testCreateFunction
* @depends testCreateExecution
* @param $function
* @param $execution
* @return array
* @throws \Exception
*/
public function testGetExecution($function, $execution): array
public function testGetExecution($execution): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_EXECUTION);
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'functionId' => $execution['functionId'],
'executionId' => $execution['_id'],
]
];
@ -405,20 +435,18 @@ class FunctionsServerTest extends Scope
}
/**
* @depends testCreateFunction
* @depends testCreateDeployment
* @param $function
* @param $deployment
* @throws \Exception
*/
public function testDeleteDeployment($function, $deployment): void
public function testDeleteDeployment($deployment): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$DELETE_DEPLOYMENT);
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'functionId' => $deployment['resourceId'],
'deploymentId' => $deployment['_id'],
]
];
@ -430,22 +458,23 @@ class FunctionsServerTest extends Scope
$this->assertIsNotArray($response['body']);
$this->assertEquals(204, $response['headers']['status-code']);
return $deployment;
}
/**
* @depends testCreateFunction
* @depends testDeleteDeployment
* @param $function
* @param $deployment
* @throws \Exception
*/
public function testDeleteFunction($function): void
public function testDeleteFunction($deployment): void
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$DELETE_FUNCTION);
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'functionId' => $deployment['resourceId'],
]
];