Skip to content

Commit 87f66fa

Browse files
change the tests
1 parent b777c6c commit 87f66fa

2 files changed

Lines changed: 61 additions & 15 deletions

File tree

src/tests/integration/test_rpc.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,37 @@ struct RpcTestConfig {
5757
}
5858
};
5959

60-
// Generate a random string of specified size
60+
// Sample sentences for generating compressible payloads
61+
static const std::vector<std::string> kSampleSentences = {
62+
"The quick brown fox jumps over the lazy dog. ",
63+
"LiveKit is a real-time communication platform for building video and "
64+
"audio applications. ",
65+
"RPC allows participants to call methods on remote peers with "
66+
"request-response semantics. ",
67+
"This test measures the performance and reliability of the RPC system. ",
68+
"WebRTC enables peer-to-peer communication for real-time media streaming. ",
69+
};
70+
71+
// Generate a payload of specified size using repeating sentences (compressible)
6172
std::string generateRandomPayload(size_t size) {
62-
static const char charset[] =
63-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
6473
static std::random_device rd;
6574
static std::mt19937 gen(rd());
66-
static std::uniform_int_distribution<> dis(0, sizeof(charset) - 2);
75+
static std::uniform_int_distribution<size_t> dis(0,
76+
kSampleSentences.size() - 1);
6777

6878
std::string result;
6979
result.reserve(size);
70-
for (size_t i = 0; i < size; ++i) {
71-
result += charset[dis(gen)];
80+
81+
// Start with a random sentence to add some variation between payloads
82+
size_t start_idx = dis(gen);
83+
84+
while (result.size() < size) {
85+
const std::string &sentence =
86+
kSampleSentences[(start_idx + result.size()) % kSampleSentences.size()];
87+
result += sentence;
7288
}
73-
return result;
89+
90+
return result.substr(0, size);
7491
}
7592

7693
// Wait for a remote participant to appear

src/tests/stress/test_rpc_stress.cpp

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ using namespace std::chrono_literals;
4040
constexpr size_t kMaxRpcPayloadSize = 15 * 1024;
4141

4242
// Default stress test duration in seconds (can be overridden by env var)
43-
constexpr int kDefaultStressDurationSeconds = 3600; // 1 hour
43+
constexpr int kDefaultStressDurationSeconds = 600; // 10mins
4444

4545
// Test configuration from environment variables
4646
struct RpcStressTestConfig {
@@ -167,20 +167,49 @@ class StressTestStats {
167167
std::map<std::string, int> error_counts_;
168168
};
169169

170-
// Generate a random string of specified size
170+
// Sample sentences for generating compressible payloads
171+
static const std::vector<std::string> kSampleSentences = {
172+
"The quick brown fox jumps over the lazy dog. ",
173+
"LiveKit is a real-time communication platform for building video and "
174+
"audio applications. ",
175+
"RPC allows participants to call methods on remote peers with "
176+
"request-response semantics. ",
177+
"This stress test measures the performance and reliability of the RPC "
178+
"system under load. ",
179+
"WebRTC enables peer-to-peer communication for real-time media streaming. ",
180+
"The payload is compressed using Zstd to reduce bandwidth and improve "
181+
"throughput. ",
182+
"Data channels provide reliable or unreliable delivery of arbitrary "
183+
"application data. ",
184+
"Participants can publish audio and video tracks to share media with "
185+
"others in the room. ",
186+
"The signaling server coordinates connection establishment between peers. ",
187+
"End-to-end encryption ensures that media content is only accessible to "
188+
"participants. ",
189+
};
190+
191+
// Generate a payload of specified size using repeating sentences (compressible)
171192
std::string generateRandomPayload(size_t size) {
172-
static const char charset[] =
173-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
174193
static thread_local std::random_device rd;
175194
static thread_local std::mt19937 gen(rd());
176-
static std::uniform_int_distribution<> dis(0, sizeof(charset) - 2);
195+
static std::uniform_int_distribution<size_t> dis(0,
196+
kSampleSentences.size() - 1);
177197

178198
std::string result;
179199
result.reserve(size);
180-
for (size_t i = 0; i < size; ++i) {
181-
result += charset[dis(gen)];
200+
201+
// Start with a random sentence to add some variation between payloads
202+
size_t start_idx = dis(gen);
203+
204+
while (result.size() < size) {
205+
// Cycle through sentences starting from a random position
206+
const std::string &sentence =
207+
kSampleSentences[(start_idx + result.size()) % kSampleSentences.size()];
208+
result += sentence;
182209
}
183-
return result;
210+
211+
// Trim to exact size
212+
return result.substr(0, size);
184213
}
185214

186215
// Wait for a remote participant to appear

0 commit comments

Comments
 (0)