rob-revisited/ide/tests/Profile/ProfilerCancelTest.php

28 lines
1.3 KiB
PHP

<?php
namespace JumPHP\Ide\Tests\Profile;
use JumPHP\Ide\Profile\Profiler;
use PHPUnit\Framework\TestCase;
/** The Profiler's Stop while a profile is being read: the job is dropped, its files deleted, the page told. */
final class ProfilerCancelTest extends TestCase
{
public function testReadingAProfileCanBeStopped(): void
{
$root = sys_get_temp_dir() . '/jumphp-prof-' . bin2hex(random_bytes(4));
mkdir($root);
$events = [];
$profiler = new Profiler($root, function (string $e, array $p) use (&$events) { $events[] = [$e, $p]; });
$prep = $profiler->prepare(['mode' => 'cpu']);
file_put_contents($profiler->store()->dir($prep['id']) . '/raw/cachegrind.out.1', "version: 1\ncmd: x\nevents: Time_(10ns) Memory_(bytes)\n");
$profiler->parse($prep['id'], ['label' => 'x', 'mode' => 'cpu']);
self::assertTrue($profiler->busy());
self::assertTrue($profiler->cancel($prep['id']));
self::assertFalse($profiler->busy());
self::assertDirectoryDoesNotExist($profiler->store()->dir($prep['id']));
self::assertSame('profile.failed', $events[array_key_last($events)][0]);
self::assertFalse($profiler->cancel($prep['id']), 'nothing left to stop');
exec('rm -rf ' . escapeshellarg($root));
}
}