Skip to content

Commit

Permalink
Added failing test case to check the StopRequest timestamp is being set
Browse files Browse the repository at this point in the history
  • Loading branch information
asgrim committed Oct 10, 2019
1 parent 6f48abd commit 3dcf743
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions tests/Integration/AgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Scoutapm\IntegrationTests;

use DateTimeImmutable;
use Exception;
use PHPUnit\Framework\TestCase;
use Psr\Log\Test\TestLogger;
Expand All @@ -12,6 +13,7 @@
use Scoutapm\Config\ConfigKey;
use Scoutapm\Connector\SocketConnector;
use Scoutapm\Extension\PotentiallyAvailableExtensionCapabilities;
use Scoutapm\Helper\Timer;
use function file_get_contents;
use function getenv;
use function gethostname;
Expand Down Expand Up @@ -127,7 +129,14 @@ public function testLoggingIsSent() : void
'BatchCommand',
[
'commands' => function (array $commands) : bool {
$requestId = $this->assertUnserializedCommandContainsPayload('StartRequest', [], reset($commands), 'request_id');
$requestId = $this->assertUnserializedCommandContainsPayload(
'StartRequest',
[
'timestamp' => [$this, 'assertValidTimestamp'],
],
reset($commands),
'request_id'
);

$controllerSpanId = $this->assertUnserializedCommandContainsPayload('StartSpan', ['operation' => 'Controller/Yay'], next($commands), 'span_id');

Expand Down Expand Up @@ -176,7 +185,15 @@ public function testLoggingIsSent() : void
$quxSpanId = $this->assertUnserializedCommandContainsPayload('StartSpan', ['operation' => 'Test/qux'], next($commands), 'span_id');
$this->assertUnserializedCommandContainsPayload('StopSpan', ['span_id' => $quxSpanId], next($commands), null);

$this->assertUnserializedCommandContainsPayload('FinishRequest', ['request_id' => $requestId], next($commands), null);
$this->assertUnserializedCommandContainsPayload(
'FinishRequest',
[
'request_id' => $requestId,
'timestamp' => [$this, 'assertValidTimestamp'],
],
next($commands),
null
);

return true;
},
Expand All @@ -186,6 +203,19 @@ public function testLoggingIsSent() : void
);
}

/** @noinspection PhpUnusedPrivateMethodInspection */
/** @throws Exception */
// phpcs:disable SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod
private function assertValidTimestamp(?string $timestamp) : bool
{
self::assertNotNull($timestamp, 'Expected a non-null timestamp, but the timestamp was null');
self::assertSame($timestamp, (new DateTimeImmutable($timestamp))->format(Timer::FORMAT_FOR_CORE_AGENT));

return true;
}

// phpcs:enable

/**
* @param string[]|callable[]|array<string, (string|callable)> $keysAndValuesToExpect
* @param mixed[][]|array<string, array<string, (string|null|array)>> $actualCommand
Expand Down

0 comments on commit 3dcf743

Please sign in to comment.