mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 11:25:52 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
74 lines
3.1 KiB
PHP
74 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pterodactyl\Tests\Pest\Unit\Services\Extensions\ExtensionRuntimeTest;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\File;
|
|
use Mockery;
|
|
use Pterodactyl\Exceptions\Extensions\InvalidExtensionException;
|
|
use Pterodactyl\Services\Extensions\ExtensionLock;
|
|
use Pterodactyl\Services\Extensions\ExtensionRuntimeRefresher;
|
|
use Pterodactyl\Tests\TestCase;
|
|
|
|
uses(TestCase::class);
|
|
|
|
test('package operations exclude competing writers and nested activation retains the lock', function (): void {
|
|
$directory = sys_get_temp_dir().'/ptero-lock-'.uniqid();
|
|
config(['extensions.directory' => $directory]);
|
|
$first = new ExtensionLock;
|
|
$second = new ExtensionLock;
|
|
try {
|
|
$first->acquire('first');
|
|
$first->acquire('nested');
|
|
expect(fn () => $second->acquire('second'))->toThrow(InvalidExtensionException::class, 'Another operation');
|
|
$first->release();
|
|
expect(fn () => $second->acquire('second'))->toThrow(InvalidExtensionException::class, 'Another operation');
|
|
$first->release();
|
|
$second->acquire('second');
|
|
$second->release();
|
|
} finally {
|
|
File::deleteDirectory($directory);
|
|
}
|
|
});
|
|
|
|
test('activation invalidates cached routes and signals existing workers to restart', function (): void {
|
|
$path = sys_get_temp_dir().'/ptero-routes-'.uniqid().'.php';
|
|
$application = Mockery::mock(\Illuminate\Contracts\Foundation\Application::class);
|
|
$application->shouldReceive('getCachedRoutesPath')->once()->andReturn($path);
|
|
File::put($path, '<?php return [];');
|
|
try {
|
|
(new ExtensionRuntimeRefresher($application))->refresh();
|
|
expect($path)->not->toBeFile();
|
|
expect(Cache::get('illuminate:queue:restart'))->toBe(now()->getTimestamp());
|
|
} finally {
|
|
File::delete($path);
|
|
}
|
|
});
|
|
|
|
test('development reload follows asset activation and rollback and stays absent outside debug mode', function (): void {
|
|
$directory = sys_get_temp_dir().'/ptero-development-'.uniqid();
|
|
config(['extensions.assets_directory' => $directory, 'app.debug' => true]);
|
|
$assets = resolve(\Pterodactyl\Services\Extensions\ExtensionAssetPublisher::class);
|
|
File::ensureDirectoryExists($directory.'/probe');
|
|
$first = str_repeat('a', 64);
|
|
$second = str_repeat('b', 64);
|
|
try {
|
|
$assets->activate('probe', $first);
|
|
expect($assets->developmentPayload('probe'))->toBeNull();
|
|
$assets->watchDevelopment('probe');
|
|
$assets->activate('probe', $second);
|
|
expect(File::get($directory.'/probe/_development'))->toBe($second);
|
|
$assets->activate('probe', $first);
|
|
expect(File::get($directory.'/probe/_development'))->toBe($first);
|
|
expect($assets->developmentPayload('probe'))->toBe(['url' => '/assets/extensions/probe/_development', 'version' => $first]);
|
|
config(['app.debug' => false]);
|
|
expect($assets->developmentPayload('probe'))->toBeNull();
|
|
$assets->stopDevelopment('probe');
|
|
expect($directory.'/probe/_development')->not->toBeFile();
|
|
} finally {
|
|
File::deleteDirectory($directory);
|
|
}
|
|
});
|