mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 11:25:52 -05:00
## Problem `Tests\Integration\Console\SchedulerTest` (telemetry is scheduled and sent only when enabled, dataset true) fails when the whole integration suite runs, with `Failed asserting that actual size 22 matches expected size 2`. It passes when the file is run on its own. ## Reproduction Run `vendor/bin/pest tests/Integration` on a fresh checkout of the 2.0 development branch with the settings from `.env.ci` (it fails the same way on Linux with PHP 8.3 and 8.4 against MariaDB 11 and MySQL 8, and on Windows). Run `vendor/bin/pest tests/Integration/Console/SchedulerTest.php` alone and it passes. ## Root cause The test creates one node and then asserts that exactly two HTTP requests were recorded: the telemetry request and the request for that node. When the scheduler test runs inside the full suite, other integration tests have already left committed node rows in the database (21 nodes existed when the test ran). The telemetry job fetches system information from every node, so each of those nodes adds another request. Only the telemetry URL was faked, so the extra requests were real outbound connection attempts to the random addresses of the leftover factory nodes. ## Fix * Fake every other URL with an empty successful response, so the test can never make real network requests. * Assert what the test is about, which is that exactly one telemetry request is sent, instead of the total number of requests. The existing assertion that the telemetry payload contains the created node is kept. ## Testing * `vendor/bin/pest tests/Integration/Console/SchedulerTest.php` passes. * The full `vendor/bin/pest tests/Integration` run no longer reports this test as failed (on Windows the remaining failures there come from missing `pdo_sqlite` and POSIX file modes and are unrelated). ## Compatibility considerations Test only change. No application code, configuration or behaviour is touched.
54 lines
2.0 KiB
PHP
54 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pterodactyl\Tests\Pest\Integration\Console\SchedulerTest;
|
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Http\Client\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Pterodactyl\Console\Scheduler;
|
|
use Pterodactyl\Models\Location;
|
|
use Pterodactyl\Models\Node;
|
|
use Pterodactyl\Models\Setting;
|
|
use Pterodactyl\Tests\Integration\IntegrationTestCase;
|
|
use Pterodactyl\Tests\Support\Fakes\FakeDaemonConfiguration;
|
|
|
|
uses(IntegrationTestCase::class, DatabaseTransactions::class);
|
|
|
|
test('telemetry is scheduled and sent only when enabled', function (bool $enabled) {
|
|
config()->set('pterodactyl.telemetry.enabled', $enabled);
|
|
$uuid = '00000000-0000-4000-8000-000000000001';
|
|
Setting::put('app:telemetry:uuid', $uuid);
|
|
$node = Node::factory()->for(Location::factory())->create();
|
|
$daemon = new FakeDaemonConfiguration;
|
|
Http::fake(['https://telemetry.pterodactyl.io' => Http::response([], 200), '*' => Http::response([], 200)]);
|
|
|
|
$schedule = new Schedule;
|
|
$this->app->make(Scheduler::class)($schedule);
|
|
$events = array_values(array_filter(
|
|
$schedule->events(),
|
|
fn ($event): bool => $event->description === 'Collect Telemetry',
|
|
));
|
|
|
|
expect($events)->toHaveCount($enabled ? 1 : 0);
|
|
|
|
if (! $enabled) {
|
|
Http::assertNothingSent();
|
|
$daemon->assertNothingHappened();
|
|
|
|
return;
|
|
}
|
|
|
|
expect($events[0]->expression)->toBe('1 0 * * *');
|
|
expect($events[0]->withoutOverlapping)->toBeTrue();
|
|
$events[0]->run($this->app);
|
|
|
|
Http::assertSent(fn (Request $request): bool => $request->url() === 'https://telemetry.pterodactyl.io'
|
|
&& $request['id'] === $uuid
|
|
&& in_array($node->uuid, array_column($request['nodes'], 'id'), true));
|
|
expect(Http::recorded(fn (Request $request): bool => $request->url() === 'https://telemetry.pterodactyl.io'))->toHaveCount(1);
|
|
$daemon->assertSystemInformationFetched();
|
|
})->with([true, false]);
|