Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldiron committed Aug 7, 2024
1 parent b6516b3 commit d395d3d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 39 deletions.
3 changes: 2 additions & 1 deletion app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ function removeAllRuntimes(Table $activeRuntimes, Orchestration $orchestration):
$duration = $endTime - $startTime;

$container = array_merge($container, [
'output' => $output,
'output' => \mb_strcut($output, 0, 20000000), // 20MB safety limit
'startTime' => $startTime,
'duration' => $duration,
]);
Expand Down Expand Up @@ -645,6 +645,7 @@ function removeAllRuntimes(Table $activeRuntimes, Orchestration $orchestration):

$activeRuntimes->del($runtimeName);

$message = \mb_substr($message, 0, null, 'UTF-8'); // Get only valid UTF8 part - removes leftover half-multibytes causing SQL errors
throw new Exception($message, $th->getCode() ?: 500);
}

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./app:/usr/local/app:rw
- ./vendor/utopia-php/orchestration:/usr/local/vendor/utopia-php/orchestration:rw
- ./src:/usr/local/src:rw
- openruntimes-builds:/storage/builds:rw
- openruntimes-functions:/storage/functions:rw
Expand Down
2 changes: 1 addition & 1 deletion tests/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function call(string $method, string $path = '', array $headers = [], arr
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}

$responseBody = curl_exec($ch);
$responseBody = curl_exec($ch);

if (isset($callback)) {
curl_close($ch);
Expand Down
9 changes: 6 additions & 3 deletions tests/ExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ public function testRestartPolicy(): void

public function testBuildLogLimit(): void
{
$size1Mb = 1024 * 1024;

$output = '';
Console::execute('cd /app/tests/resources/functions/php-build-logs && tar --exclude code.tar.gz -czf code.tar.gz .', '', $output);

Expand All @@ -436,13 +438,14 @@ public function testBuildLogLimit(): void
'destination' => '/storage/builds/test',
'entrypoint' => 'index.php',
'image' => 'openruntimes/php:v4-8.1',
'command' => 'tar -zxf /tmp/code.tar.gz -C /mnt/code && helpers/build.sh "sh logs_failure.sh"'
'command' => 'tar -zxf /tmp/code.tar.gz -C /mnt/code && helpers/build.sh "sh logs_failure.sh"',
'remove' => false
];

$response = $this->client->call(Client::METHOD_POST, '/runtimes', [], $params);

$this->assertEquals(400, $response['headers']['status-code']);
$this->assertGreaterThanOrEqual(1028*10, \strlen($response['body']['message']));
$this->assertGreaterThanOrEqual($size1Mb * 14, \strlen($response['body']['message']));

$output = '';
Console::execute('cd /app/tests/resources/functions/php-build-logs && tar --exclude code.tar.gz -czf code.tar.gz .', '', $output);
Expand All @@ -460,7 +463,7 @@ public function testBuildLogLimit(): void
$response = $this->client->call(Client::METHOD_POST, '/runtimes', [], $params);

$this->assertEquals(201, $response['headers']['status-code']);
$this->assertGreaterThanOrEqual(1028*10, \strlen($response['body']['output']));
$this->assertGreaterThanOrEqual($size1Mb * 14, \strlen($response['body']['output']));
}

/**
Expand Down
38 changes: 20 additions & 18 deletions tests/resources/functions/php-build-logs/logs_failure.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
set -e

CHARS_128="11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
CHARS_1024="$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128"
CHARS_1KB="$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128"
CHARS_16KB="$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB"
CHARS_128KB="$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB"
CHARS_1MB="$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB"

# 1 MB
echo -n $CHARS_1024
echo -n $CHARS_1MB

# Exception message length is 1MB max. Logs below ensure build logs arent limited by it

# 2 MB
echo -n $CHARS_1024
echo -n $CHARS_1MB

# Up to 20MB is valid, so we add more to ensure larger logs are also fine

# 15 MB
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB

# Cause exception
exit 1
exit 1
35 changes: 19 additions & 16 deletions tests/resources/functions/php-build-logs/logs_success.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
set -e

CHARS_128="11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
CHARS_1024="$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128"
CHARS_1KB="$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128"
CHARS_16KB="$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB"
CHARS_128KB="$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB"
CHARS_1MB="$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB"

# 1 MB
echo -n $CHARS_1024
echo -n $CHARS_1MB

# Exception message length is 1MB max. Logs below ensure build logs arent limited by it

# 2 MB
echo -n $CHARS_1024
echo -n $CHARS_1MB

# Up to 20MB is valid, so we add more to ensure larger logs are also fine

# 15 MB
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1024
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB
echo -n $CHARS_1MB

0 comments on commit d395d3d

Please sign in to comment.