Skip to content

Commit

Permalink
Infra: fix regression in unit tests when executed directly on termina…
Browse files Browse the repository at this point in the history
…l console (#2169)
  • Loading branch information
canepat authored Jul 8, 2024
1 parent d95fa93 commit e6e7344
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
18 changes: 10 additions & 8 deletions silkworm/infra/common/log_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,16 @@ TEST_CASE("LogBuffer", "[silkworm][common][log]") {
}

SECTION("Settings disables colorized output depending on TTY") {
const bool is_terminal = is_terminal_stdout() && is_terminal_stderr();

// Default output is NOT colorized on non-TTY terminal
LogBuffer_ForTest<Level::kInfo>{"test0", {"key1", "value1", "key2", "value2"}}; // temporary log object, flush on dtor
const auto cerr_output0{string_cerr.str()};
CHECK(absl::StrContains(cerr_output0, "test0"));
CHECK(absl::StrContains(cerr_output0, key_value("key1", "value1")));
CHECK(absl::StrContains(cerr_output0, key_value("key2", "value2")));
CHECK(!absl::StrContains(cerr_output0, prettified_key_value("key1", "value1")));
CHECK(!absl::StrContains(cerr_output0, prettified_key_value("key2", "value2")));
CHECK(absl::StrContains(cerr_output0, key_value("key1", "value1")) == !is_terminal);
CHECK(absl::StrContains(cerr_output0, key_value("key2", "value2")) == !is_terminal);
CHECK(absl::StrContains(cerr_output0, prettified_key_value("key1", "value1")) == is_terminal);
CHECK(absl::StrContains(cerr_output0, prettified_key_value("key2", "value2")) == is_terminal);

// Reset cerr replacement stream
string_cerr.str("");
Expand All @@ -156,10 +158,10 @@ TEST_CASE("LogBuffer", "[silkworm][common][log]") {
LogBuffer_ForTest<Level::kInfo>{"test2", {"key3", "value3", "key4", "value4"}}; // temporary log object, flush on dtor
const auto cerr_output2{string_cerr.str()};
CHECK(absl::StrContains(cerr_output2, "test2"));
CHECK(absl::StrContains(cerr_output2, key_value("key3", "value3")));
CHECK(absl::StrContains(cerr_output2, key_value("key4", "value4")));
CHECK(!absl::StrContains(cerr_output2, prettified_key_value("key3", "value3")));
CHECK(!absl::StrContains(cerr_output2, prettified_key_value("key4", "value4")));
CHECK(absl::StrContains(cerr_output2, key_value("key3", "value3")) == !is_terminal);
CHECK(absl::StrContains(cerr_output2, key_value("key4", "value4")) == !is_terminal);
CHECK(absl::StrContains(cerr_output2, prettified_key_value("key3", "value3")) == is_terminal);
CHECK(absl::StrContains(cerr_output2, prettified_key_value("key4", "value4")) == is_terminal);
}

SECTION("Settings disable colorized output if log file present") {
Expand Down
15 changes: 15 additions & 0 deletions silkworm/infra/concurrency/context_pool_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ TEST_CASE("ContextPool", "[silkworm][concurrency][Context]") {
context_pool.stop();
CHECK_NOTHROW(context_pool.join());
}

SECTION("stop/start w/o contexts") {
ContextPool context_pool{2};
REQUIRE(context_pool.num_contexts() == 0);
CHECK_NOTHROW(context_pool.stop());
CHECK_NOTHROW(context_pool.start());
}

SECTION("stop/start w/ contexts") {
ContextPool context_pool{2};
context_pool.add_context(Context{0, WaitMode::blocking});
context_pool.add_context(Context{1, WaitMode::blocking});
CHECK_NOTHROW(context_pool.stop());
CHECK_NOTHROW(context_pool.start());
}
}
#endif // SILKWORM_SANITIZE

Expand Down

0 comments on commit e6e7344

Please sign in to comment.