This repository has been archived by the owner on May 27, 2024. It is now read-only.
forked from DataDog/php-datadogstatsd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c97a240
commit 044aa73
Showing
5 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace DataDog\UnitTests\DogStatsd; | ||
|
||
use DataDog\DogStatsd; | ||
use DataDog\TestHelpers\SocketSpyTestCase; | ||
|
||
class CountSentMessagesTest extends SocketSpyTestCase | ||
{ | ||
public function testReportDoesNotSendIfBufferNotFilled() | ||
{ | ||
$batchedDog = new DogStatsd(); | ||
|
||
$batchedDog->report('some fake UDP message'); | ||
|
||
$spy = $this->getSocketSpy(); | ||
|
||
$this->assertSame( | ||
1, | ||
count($spy->argsFromSocketSendtoCalls), | ||
'Should sent UDP message' | ||
); | ||
|
||
$this->assertSame( | ||
0, | ||
count($spy->argsFromSocketCloseCalls), | ||
'Socket should be not closed' | ||
); | ||
} | ||
|
||
public function testReportSendsOnceBufferIsFilled() | ||
{ | ||
$batchedDog = new DogStatsd(); | ||
|
||
$batchedDog::$maxCountMessagesOnSocketSession = 2; | ||
|
||
$udpMessage = 'some fake UDP message'; | ||
|
||
$spy = $this->getSocketSpy(); | ||
|
||
$batchedDog->gauge($udpMessage . '1', 21); | ||
$batchedDog->gauge($udpMessage . '2', 21); | ||
$batchedDog->gauge($udpMessage . '3', 21); | ||
|
||
$this->assertSame( | ||
3, | ||
count($spy->argsFromSocketSendtoCalls), | ||
'Should send all UDP messages' | ||
); | ||
$this->assertSame( | ||
1, | ||
count($spy->argsFromSocketCloseCalls), | ||
'Socket was not closed' | ||
); | ||
|
||
$this->assertSame( | ||
"some fake UDP message1:21|g\n", | ||
$spy->argsFromSocketSendtoCalls[0][1], | ||
'Should concatenate UDP messages with newlines' | ||
); | ||
$this->assertSame( | ||
"some fake UDP message2:21|g\n", | ||
$spy->argsFromSocketSendtoCalls[1][1], | ||
'Should concatenate UDP messages with newlines' | ||
); | ||
$this->assertSame( | ||
"some fake UDP message3:21|g\n", | ||
$spy->argsFromSocketSendtoCalls[2][1], | ||
'Should concatenate UDP messages with newlines' | ||
); | ||
} | ||
} |