-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agents: implement data handle ring buffer
Add a basic `RingBuffer<T>` implementation to `nsolid_util.h` with accompanying tests. Use it for ZMQ `data` channel messages, so we're able to buffer up to `MAX_DATA_BUFFER_SIZE` messages in case of channel disconnection. Fixes problems observed while load testing the agent, where data messages were generated before the actual `data` channel connection was established and were actually dropped.
- Loading branch information
1 parent
13c420e
commit 63ebaa6
Showing
5 changed files
with
153 additions
and
59 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,39 @@ | ||
#include "gtest/gtest.h" | ||
#include "nsolid/nsolid_util.h" | ||
|
||
using node::nsolid::utils::RingBuffer; | ||
|
||
TEST(RingBufferTest, Basic) { | ||
// Create a buffer of size 3. | ||
RingBuffer<int> buffer(3); | ||
|
||
// Test that the buffer is initially empty. | ||
EXPECT_TRUE(buffer.empty()); | ||
|
||
// Push some elements into the buffer. | ||
buffer.push(1); | ||
buffer.push(2); | ||
buffer.push(3); | ||
|
||
// Test that the buffer is not empty. | ||
EXPECT_FALSE(buffer.empty()); | ||
|
||
// Test that the front of the buffer is the first element pushed. | ||
EXPECT_EQ(buffer.front(), 1); | ||
|
||
// Pop an element and test that the front of the buffer is the second element | ||
// pushed. | ||
buffer.pop(); | ||
EXPECT_EQ(buffer.front(), 2); | ||
|
||
// Push another element and test that the front of the buffer is still the | ||
// second element pushed. | ||
buffer.push(4); | ||
EXPECT_EQ(buffer.front(), 2); | ||
|
||
// Push another element. This should cause the second element to be popped | ||
// (since the buffer size is 3), so the front of the buffer should now be the | ||
// third element pushed. | ||
buffer.push(5); | ||
EXPECT_EQ(buffer.front(), 3); | ||
} |