From cde8f22ce1a8e6ea66086488a532db5dafe8a739 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 30 Apr 2023 02:16:11 +0800 Subject: [PATCH] fix: short code global test before speed up --- test/codec/short_code.cc | 48 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/test/codec/short_code.cc b/test/codec/short_code.cc index 01a60b5..740486f 100644 --- a/test/codec/short_code.cc +++ b/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 { std::vector 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]) {