-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.cc
41 lines (38 loc) · 1.19 KB
/
client.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "craft/client.h"
#include <random>
std::string generateRandomString(int n) {
std::string result;
static const char alphanum[] =
"abcdefghijklmnopqrstuvwxyz"; // 可以在这里添加其他字符
std::srand(std::time(nullptr)); // 使用当前时间初始化随机种子
for (int i = 0; i < n; ++i) {
result += alphanum[std::rand() % (sizeof(alphanum) - 1)];
}
return result;
}
static std::string randomBytes() {
int random_int = std::rand() % 10;
if (random_int < 3) {
return generateRandomString((std::rand() % 1500) + 100);
} else {
return generateRandomString((std::rand() % 500) + 1);
}
}
int main(int argc, char **argv) {
spdlog::set_level(spdlog::level::debug);
static int count = 0;
// simple stress test
for (int i = 0; i < 2; i++) {
std::thread([&] {
CRaftClient client;
while (true) {
auto command = randomBytes();
ClientResult res = client.submitCommand(command);
std::cout << res.is_timeout << std::endl;
sleep(std::rand() % 4);
}
}).detach();
}
sleep(10000000);
return 0;
}