mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
fix: realtime tests
This commit is contained in:
@@ -6,14 +6,14 @@ use Appwrite\ID;
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
use Tests\E2E\Scopes\SideServer;
|
||||
use Utopia\Database\Helpers\Role;
|
||||
|
||||
class FunctionsScheduleTest extends Scope
|
||||
{
|
||||
use FunctionsBase;
|
||||
use ProjectCustom;
|
||||
use SideClient;
|
||||
use SideServer;
|
||||
|
||||
public function testCreateScheduledExecution()
|
||||
{
|
||||
@@ -92,16 +92,27 @@ class FunctionsScheduleTest extends Scope
|
||||
$futureTime = (new \DateTime())->add(new \DateInterval('PT2M')); // 2 minute in the future
|
||||
$futureTime->setTime($futureTime->format('H'), $futureTime->format('i'), 0, 0);
|
||||
|
||||
$execution = $this->createExecution($functionId, [
|
||||
'async' => true,
|
||||
'scheduledAt' => $futureTime->format(\DateTime::ATOM),
|
||||
'path' => '/custom-path',
|
||||
'method' => 'PATCH',
|
||||
'body' => 'custom-body',
|
||||
'headers' => [
|
||||
'x-custom-header' => 'custom-value'
|
||||
|
||||
$execution = $this->client->call(
|
||||
Client::METHOD_POST,
|
||||
'/functions/' . $functionId . '/executions',
|
||||
[
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'origin' => 'http://localhost',
|
||||
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $this->getUser()['session'],
|
||||
],
|
||||
[
|
||||
'async' => true,
|
||||
'scheduledAt' => $futureTime->format(\DateTime::ATOM),
|
||||
'path' => '/custom-path',
|
||||
'method' => 'PATCH',
|
||||
'body' => 'custom-body',
|
||||
'headers' => [
|
||||
'x-custom-header' => 'custom-value'
|
||||
]
|
||||
]
|
||||
]);
|
||||
);
|
||||
$executionId = $execution['body']['$id'];
|
||||
|
||||
$this->assertEquals(202, $execution['headers']['status-code']);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Tests\E2E\Services\Realtime;
|
||||
|
||||
use CURLFile;
|
||||
use Utopia\CLI\Console;
|
||||
use WebSocket\Client as WebSocketClient;
|
||||
use WebSocket\ConnectionException;
|
||||
|
||||
@@ -71,4 +73,23 @@ trait RealtimeBase
|
||||
$this->expectException(ConnectionException::class); // Check if server disconnnected client
|
||||
$client->close();
|
||||
}
|
||||
|
||||
// Function-related methods
|
||||
protected string $output = '';
|
||||
|
||||
protected function packageFunction(string $function = 'php'): CURLFile
|
||||
{
|
||||
$folderPath = realpath(__DIR__ . '/../../../resources/functions') . "/$function";
|
||||
$tarPath = "$folderPath/code.tar.gz";
|
||||
|
||||
if (!file_exists($tarPath)) {
|
||||
Console::execute("cd $folderPath && tar --exclude code.tar.gz -czf code.tar.gz .", '', $this->output);
|
||||
}
|
||||
|
||||
if (filesize($tarPath) > 1024 * 1024 * 5) {
|
||||
throw new \Exception('Code package is too large. Use the chunked upload method instead.');
|
||||
}
|
||||
|
||||
return new CURLFile($tarPath, 'application/x-gzip', \basename($tarPath));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Helpers\Permission;
|
||||
use Utopia\Database\Helpers\Role;
|
||||
@@ -1271,19 +1270,13 @@ class RealtimeCustomClientTest extends Scope
|
||||
$this->assertEquals($function['headers']['status-code'], 201);
|
||||
$this->assertNotEmpty($function['body']['$id']);
|
||||
|
||||
$folder = 'timeout';
|
||||
$output = '';
|
||||
$code = realpath(__DIR__ . '/../../../resources/functions') . "/{$folder}/code.tar.gz";
|
||||
|
||||
Console::execute('cd ' . realpath(__DIR__ . "/../../../resources/functions") . "/{$folder} && tar --exclude code.tar.gz -czf code.tar.gz .", '', $output);
|
||||
|
||||
$deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge([
|
||||
'content-type' => 'multipart/form-data',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'entrypoint' => 'index.php',
|
||||
'code' => new CURLFile($code, 'application/x-gzip', basename($code)),
|
||||
'code' => $this->packageFunction('timeout'),
|
||||
'activate' => true
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user