Skip to content

Commit

Permalink
Use the round method to store miliseconds on RPCLogEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Hectorhammett committed Nov 25, 2024
1 parent 98054c8 commit 37a98a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Logging/RpcLogEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function __construct(null|float $startTime = null)
$this->milliseconds = round(microtime(true) * 1000);

if ($startTime) {
$this->latency = (int) $this->milliseconds - $startTime;
$this->latency = (int) round($this->milliseconds - $startTime);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,31 @@

namespace Google\Auth\Tests\Logging;

use Google\Auth\Logging\LogEvent;
use Google\Auth\Logging\RpcLogEvent;
use Google\Auth\Tests\BaseTest;

class LogEventTest extends BaseTest
class RpcLogEventTest extends BaseTest
{
public function testInstanceAddsTimestamp()
{
$item = new LogEvent();
$item = new RpcLogEvent();
$this->assertNotNull($item->timestamp);
}

public function testConstructorWithoutParameterHasNoLatency()
{
$item = new LogEvent();
$item = new RpcLogEvent();
$this->assertNull($item->latency);
}

public function testConstructorWithParameterHasLatencySet()
{
$currentMicrotimeInMillis = microtime(true) * 1000;
$item = new LogEvent($currentMicrotimeInMillis);
// We sustract 1000 ms to simulate a microtime 1000ms in the past
$previousMicrotimeInMillis = (microtime(true) * 1000) - 1000;
$item = new RpcLogEvent($previousMicrotimeInMillis);
$this->assertNotNull($item->latency);

// Adding a delta to the test due timing on how this executes
$this->assertEqualsWithDelta(1000, $item->latency, 5);
}
}

0 comments on commit 37a98a1

Please sign in to comment.