Browse Source

fix: short code global test before speed up

master
Dnomd343 2 years ago
parent
commit
cde8f22ce1
  1. 48
      test/codec/short_code.cc

48
test/codec/short_code.cc

@ -44,30 +44,6 @@ TEST(ShortCode, validity) {
SHOULD_PANIC(ShortCode::from_string("Z9EFV")) // out of short code range
}
TEST(ShortCode, speed_up) {
std::thread threads[4];
/// speed up to normal mode
EXPECT_EQ(BasicRanges::status(), BasicRanges::NOT_INIT);
for (auto &t : threads) {
t = std::thread(ShortCode::speed_up, ShortCode::NORMAL);
}
usleep(1000); // wait 1ms -> avoid mutex unlocked
EXPECT_EQ(BasicRanges::status(), BasicRanges::BUILDING);
for (auto &t : threads) { t.join(); }
EXPECT_EQ(BasicRanges::status(), BasicRanges::AVAILABLE);
/// speed up to fast mode
EXPECT_EQ(AllCases::status(), AllCases::NOT_INIT);
for (auto &t : threads) {
t = std::thread(ShortCode::speed_up, ShortCode::FAST);
}
usleep(1000); // wait 1ms -> avoid mutex unlocked
EXPECT_EQ(AllCases::status(), AllCases::BUILDING);
for (auto &t : threads) { t.join(); }
EXPECT_EQ(AllCases::status(), AllCases::AVAILABLE);
}
TEST(ShortCode, DISABLED_global) {
auto check = [](uint32_t start, uint32_t end) -> std::vector<uint64_t> {
std::vector<uint64_t> archive;
@ -101,6 +77,30 @@ TEST(ShortCode, DISABLED_global) {
}
}
TEST(ShortCode, speed_up) {
std::thread threads[4];
/// speed up to normal mode
EXPECT_EQ(BasicRanges::status(), BasicRanges::NOT_INIT);
for (auto &t : threads) {
t = std::thread(ShortCode::speed_up, ShortCode::NORMAL);
}
usleep(1000); // wait 1ms -> avoid mutex unlocked
EXPECT_EQ(BasicRanges::status(), BasicRanges::BUILDING);
for (auto &t : threads) { t.join(); }
EXPECT_EQ(BasicRanges::status(), BasicRanges::AVAILABLE);
/// speed up to fast mode
EXPECT_EQ(AllCases::status(), AllCases::NOT_INIT);
for (auto &t : threads) {
t = std::thread(ShortCode::speed_up, ShortCode::FAST);
}
usleep(1000); // wait 1ms -> avoid mutex unlocked
EXPECT_EQ(AllCases::status(), AllCases::BUILDING);
for (auto &t : threads) { t.join(); }
EXPECT_EQ(AllCases::status(), AllCases::AVAILABLE);
}
TEST(ShortCode, code_verify) { // test all layout
auto test = [](uint64_t head) {
for (const auto &range : AllCases::fetch()[head]) {

Loading…
Cancel
Save