Use Random::fast_bool.
GitOrigin-RevId: 42da8a237c6dfbb6e72bc5b21482891b6c9d58b5
This commit is contained in:
parent
291a9ff43b
commit
582206d641
@ -114,7 +114,7 @@ void SecretChatsManager::cancel_chat(SecretChatId secret_chat_id, Promise<> prom
|
||||
|
||||
void SecretChatsManager::send_message(SecretChatId secret_chat_id, tl_object_ptr<secret_api::decryptedMessage> message,
|
||||
tl_object_ptr<telegram_api::InputEncryptedFile> file, Promise<> promise) {
|
||||
// message->message_ = Random::fast(0, 1) ? string(1, static_cast<char>(0x80)) : "a";
|
||||
// message->message_ = Random::fast_bool() ? string(1, static_cast<char>(0x80)) : "a";
|
||||
auto actor = get_chat_actor(secret_chat_id.get());
|
||||
auto safe_promise = SafePromise<>(std::move(promise), Status::Error(400, "Can't find secret chat"));
|
||||
send_closure(actor, &SecretChatActor::send_message, std::move(message), std::move(file), std::move(safe_promise));
|
||||
|
@ -1108,7 +1108,7 @@ class CliClient final : public Actor {
|
||||
std::tie(excluded_chat_ids, filter) = split(filter);
|
||||
|
||||
auto rand_bool = [] {
|
||||
return Random::fast(0, 1) == 1;
|
||||
return Random::fast_bool();
|
||||
};
|
||||
|
||||
return td_api::make_object<td_api::chatFilter>(
|
||||
@ -2748,7 +2748,7 @@ class CliClient final : public Actor {
|
||||
auto chat = as_chat_id(chat_id);
|
||||
send_request(td_api::make_object<td_api::forwardMessages>(
|
||||
chat, as_chat_id(from_chat_id), as_message_ids(message_ids), default_message_send_options(), op[0] == 'c',
|
||||
Random::fast(0, 1) == 1));
|
||||
Random::fast_bool()));
|
||||
} else if (op == "resend") {
|
||||
string chat_id;
|
||||
string message_ids;
|
||||
@ -2772,7 +2772,7 @@ class CliClient final : public Actor {
|
||||
} else if (op == "cc" || op == "CreateCall") {
|
||||
send_request(td_api::make_object<td_api::createCall>(
|
||||
as_user_id(args), td_api::make_object<td_api::callProtocol>(true, true, 65, 65, vector<string>{"2.6", "3.0"}),
|
||||
Random::fast(0, 1) == 1));
|
||||
Random::fast_bool()));
|
||||
} else if (op == "ac" || op == "AcceptCall") {
|
||||
send_request(td_api::make_object<td_api::acceptCall>(
|
||||
as_call_id(args),
|
||||
@ -2785,7 +2785,7 @@ class CliClient final : public Actor {
|
||||
std::tie(call_id, is_disconnected) = split(args);
|
||||
|
||||
send_request(td_api::make_object<td_api::discardCall>(as_call_id(call_id), as_bool(is_disconnected), 0,
|
||||
Random::fast(0, 1) == 1, 0));
|
||||
Random::fast_bool(), 0));
|
||||
} else if (op == "scr" || op == "SendCallRating") {
|
||||
string call_id;
|
||||
string rating;
|
||||
@ -3280,8 +3280,7 @@ class CliClient final : public Actor {
|
||||
|
||||
td_api::object_ptr<td_api::messageCopyOptions> copy_options;
|
||||
if (op == "scopy") {
|
||||
copy_options =
|
||||
td_api::make_object<td_api::messageCopyOptions>(true, Random::fast(0, 1) == 0, as_caption("_as_d"));
|
||||
copy_options = td_api::make_object<td_api::messageCopyOptions>(true, Random::fast_bool(), as_caption("_as_d"));
|
||||
}
|
||||
|
||||
send_message(chat_id,
|
||||
@ -4348,7 +4347,7 @@ class CliClient final : public Actor {
|
||||
}
|
||||
BufferSlice block(it->part_size);
|
||||
FileFd::open(it->source, FileFd::Flags::Read).move_as_ok().pread(block.as_slice(), it->local_size).ensure();
|
||||
if (Random::fast(0, 1) == 0) {
|
||||
if (Random::fast_bool()) {
|
||||
auto open_flags = FileFd::Flags::Write | (it->local_size ? 0 : FileFd::Flags::Truncate | FileFd::Flags::Create);
|
||||
FileFd::open(it->destination, open_flags).move_as_ok().pwrite(block.as_slice(), it->local_size).ensure();
|
||||
} else {
|
||||
|
@ -261,7 +261,7 @@ class MainQueryActor final : public Actor {
|
||||
void wakeup() override {
|
||||
int cnt = 100000;
|
||||
while (out_cnt_ < in_cnt_ + 100 && out_cnt_ < cnt) {
|
||||
if (Random::fast(0, 1)) {
|
||||
if (Random::fast_bool()) {
|
||||
send_closure(rand_elem(actors_), &QueryActor::query, create_query());
|
||||
} else {
|
||||
send_closure_later(rand_elem(actors_), &QueryActor::query, create_query());
|
||||
@ -306,7 +306,7 @@ class SimpleActor final : public Actor {
|
||||
return;
|
||||
}
|
||||
q_++;
|
||||
p_ = Random::fast(0, 1) ? 1 : 10000;
|
||||
p_ = Random::fast_bool() ? 1 : 10000;
|
||||
auto future = Random::fast(0, 3) == 0 ? send_promise<ActorSendType::Immediate>(worker_, &Worker::query, q_, p_)
|
||||
: send_promise<ActorSendType::Later>(worker_, &Worker::query, q_, p_);
|
||||
if (future.is_ready()) {
|
||||
|
@ -34,7 +34,7 @@ vector<string> rand_split(Slice str) {
|
||||
size_t pos = 0;
|
||||
while (pos < str.size()) {
|
||||
size_t len;
|
||||
if (Random::fast(0, 1) == 1) {
|
||||
if (Random::fast_bool()) {
|
||||
len = Random::fast(1, 10);
|
||||
} else {
|
||||
len = Random::fast(100, 200);
|
||||
|
@ -42,7 +42,7 @@ TEST(EpochBaseMemoryReclamation, stress) {
|
||||
locker.retire();
|
||||
}
|
||||
if (td::Random::fast(0, 5) == 0) {
|
||||
std::string *new_str = new std::string(td::Random::fast(0, 1) == 0 ? "one" : "twotwo");
|
||||
std::string *new_str = new std::string(td::Random::fast_bool() ? "one" : "twotwo");
|
||||
if (node.name_.compare_exchange_strong(str, new_str, std::memory_order_acq_rel)) {
|
||||
locker.retire(str);
|
||||
} else {
|
||||
|
@ -36,7 +36,7 @@ TEST(HazardPointers, stress) {
|
||||
}
|
||||
holder.clear();
|
||||
if (td::Random::fast(0, 5) == 0) {
|
||||
std::string *new_str = new std::string(td::Random::fast(0, 1) == 0 ? "one" : "twotwo");
|
||||
std::string *new_str = new std::string(td::Random::fast_bool() ? "one" : "twotwo");
|
||||
if (node.name_.compare_exchange_strong(str, new_str, std::memory_order_acq_rel)) {
|
||||
hazard_pointers.retire(thread_id, str);
|
||||
} else {
|
||||
|
@ -18,7 +18,7 @@ TEST(OrderedEventsProcessor, random) {
|
||||
int offset = 1000000;
|
||||
std::vector<std::pair<int, int>> v;
|
||||
for (int i = 0; i < n; i++) {
|
||||
auto shift = td::Random::fast(0, 1) ? td::Random::fast(0, d) : td::Random::fast(0, 1) * d;
|
||||
auto shift = td::Random::fast_bool() ? td::Random::fast(0, d) : td::Random::fast(0, 1) * d;
|
||||
v.push_back({i + shift, i + offset});
|
||||
}
|
||||
std::sort(v.begin(), v.end());
|
||||
|
@ -37,16 +37,16 @@ TEST(Buffer, buffer_builder) {
|
||||
int r = l;
|
||||
BufferBuilder builder(splitted_str[l], 123, 1000);
|
||||
while (l != 0 || r != static_cast<int32>(splitted_str.size()) - 1) {
|
||||
if (l == 0 || (Random::fast(0, 1) == 1 && r != static_cast<int32>(splitted_str.size() - 1))) {
|
||||
if (l == 0 || (Random::fast_bool() && r != static_cast<int32>(splitted_str.size() - 1))) {
|
||||
r++;
|
||||
if (Random::fast(0, 1) == 1) {
|
||||
if (Random::fast_bool()) {
|
||||
builder.append(splitted_str[r]);
|
||||
} else {
|
||||
builder.append(BufferSlice(splitted_str[r]));
|
||||
}
|
||||
} else {
|
||||
l--;
|
||||
if (Random::fast(0, 1) == 1) {
|
||||
if (Random::fast_bool()) {
|
||||
builder.prepend(splitted_str[l]);
|
||||
} else {
|
||||
builder.prepend(BufferSlice(splitted_str[l]));
|
||||
|
@ -99,8 +99,8 @@ static string make_http_query(string content, bool is_chunked, bool is_gzip, dou
|
||||
}
|
||||
|
||||
static string rand_http_query(string content) {
|
||||
bool is_chunked = Random::fast(0, 1) == 0;
|
||||
bool is_gzip = Random::fast(0, 1) == 0;
|
||||
bool is_chunked = Random::fast_bool();
|
||||
bool is_gzip = Random::fast_bool();
|
||||
return make_http_query(std::move(content), is_chunked, is_gzip);
|
||||
}
|
||||
|
||||
|
@ -964,7 +964,7 @@ TEST(MessageEntities, fix_formatted_text) {
|
||||
{td::MessageEntity::Type::Italic, 2, 11}});
|
||||
|
||||
for (size_t test_n = 0; test_n < 100000; test_n++) {
|
||||
bool is_url = td::Random::fast(0, 1) == 1;
|
||||
bool is_url = td::Random::fast_bool();
|
||||
td::int32 url_offset = 0;
|
||||
td::int32 url_end = 0;
|
||||
if (is_url) {
|
||||
|
@ -786,7 +786,7 @@ class Master : public Actor {
|
||||
return false;
|
||||
}
|
||||
void send_net_query(NetQueryPtr query, ActorShared<NetQueryCallback> callback, bool ordered) {
|
||||
if (can_fail(query) && Random::fast(0, 1) == 0) {
|
||||
if (can_fail(query) && Random::fast_bool()) {
|
||||
LOG(INFO) << "Fail query " << query;
|
||||
auto resend_promise =
|
||||
PromiseCreator::lambda([id = actor_shared(this, get_link_token()), callback_actor = callback.get(),
|
||||
|
@ -861,7 +861,7 @@ TEST(Client, SimpleMulti) {
|
||||
|
||||
for (size_t i = 0; i < clients.size(); i++) {
|
||||
clients[i].send({i + 2, td::make_tl_object<td::td_api::testSquareInt>(3)});
|
||||
if (Random::fast(0, 1) == 1) {
|
||||
if (Random::fast_bool()) {
|
||||
clients[i].send({1, td::make_tl_object<td::td_api::close>()});
|
||||
}
|
||||
}
|
||||
@ -974,7 +974,7 @@ TEST(Client, Close) {
|
||||
can_stop_receive = true;
|
||||
});
|
||||
|
||||
auto max_continue_send = td::Random::fast(0, 1) ? 0 : 1000;
|
||||
auto max_continue_send = td::Random::fast_bool() ? 0 : 1000;
|
||||
td::thread receive_thread([&] {
|
||||
while (true) {
|
||||
auto response = client.receive(100.0);
|
||||
@ -1000,7 +1000,7 @@ TEST(Client, Close) {
|
||||
}
|
||||
});
|
||||
|
||||
td::usleep_for((td::Random::fast(0, 1) ? 0 : 1000) * (td::Random::fast(0, 1) ? 1 : 50));
|
||||
td::usleep_for((td::Random::fast_bool() ? 0 : 1000) * (td::Random::fast_bool() ? 1 : 50));
|
||||
client.send({1, td::make_tl_object<td::td_api::close>()});
|
||||
|
||||
send_thread.join();
|
||||
@ -1033,7 +1033,7 @@ TEST(Client, ManagerClose) {
|
||||
can_stop_receive = true;
|
||||
});
|
||||
|
||||
auto max_continue_send = td::Random::fast(0, 1) ? 0 : 1000;
|
||||
auto max_continue_send = td::Random::fast_bool() ? 0 : 1000;
|
||||
td::thread receive_thread([&] {
|
||||
while (true) {
|
||||
auto response = client_manager.receive(100.0);
|
||||
@ -1059,7 +1059,7 @@ TEST(Client, ManagerClose) {
|
||||
}
|
||||
});
|
||||
|
||||
td::usleep_for((td::Random::fast(0, 1) ? 0 : 1000) * (td::Random::fast(0, 1) ? 1 : 50));
|
||||
td::usleep_for((td::Random::fast_bool() ? 0 : 1000) * (td::Random::fast_bool() ? 1 : 50));
|
||||
client_manager.send(client_id, 1, td::make_tl_object<td::td_api::close>());
|
||||
|
||||
send_thread.join();
|
||||
|
Loading…
Reference in New Issue
Block a user