Skip to content

Commit

Permalink
Add test for sending with RPS limit
Browse files Browse the repository at this point in the history
  • Loading branch information
markinjapan committed Aug 2, 2024
1 parent 17bf473 commit 424a04d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/Handler/CloudWatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,53 @@ public function testSendsBatches(): void
$handler->close();
}

public function testSendWithRPSLimit(): void
{
$this->prepareMocks();

$this
->clientMock
->expects($this->exactly(3))
->method('PutLogEvents')
->willReturnCallback(function (array $data) {
$this->assertStringContainsString('record', $data['logEvents'][0]['message']);

return $this->awsResultMock;
});

$handler = new CloudWatch(
$this->clientMock,
$this->groupName,
$this->streamName,
14,
1,
[],
Level::Debug,
true,
true,
true,
1
);

$reflection = new \ReflectionClass($handler);
$savedTime = $reflection->getProperty('savedTime');
$savedTime->setValue($handler, new \DateTimeImmutable());

$reflectionMethod = $reflection->getMethod('initialize');
$reflectionMethod->setAccessible(true);
$reflectionMethod->invoke($handler);

// Initial log entry
$handler->handle($this->getRecord(Level::Debug, 'record'));

// Another log entry immediately after
$handler->handle($this->getRecord(Level::Debug, 'record'));

// Final log entry 1 second later
sleep(1);
$handler->handle($this->getRecord(Level::Debug, 'record'));
}

public function testFormatter(): void
{
$handler = $this->getCUT();
Expand Down

0 comments on commit 424a04d

Please sign in to comment.