Skip to content

Extract logging tests to a separate executable.#2087

Closed
Dimi1010 wants to merge 1 commit into
seladb:devfrom
Dimi1010:fix/logger-tests
Closed

Extract logging tests to a separate executable.#2087
Dimi1010 wants to merge 1 commit into
seladb:devfrom
Dimi1010:fix/logger-tests

Conversation

@Dimi1010

@Dimi1010 Dimi1010 commented Mar 21, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2083

Bug

After the logger tests are ran, the logger configuration is restored to its default state instead of to the state it was prior to the test being ran.

Proposed fix

A proposed fix is to extract all logger tests to a separate executable. This is because the logger tests modify the logger configuration and callback, The callback specifically cannot be extracted from the logger, so a better solution would be to separate those tests in a new program.

@codecov

codecov Bot commented Mar 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.52941% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.69%. Comparing base (c53340e) to head (2cd4afd).
⚠️ Report is 2 commits behind head on dev.

Files with missing lines Patch % Lines
Tests/Logger++Test/main.cpp 36.76% 39 Missing and 4 partials ⚠️
Tests/Logger++Test/LoggerTests.cpp 98.03% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##              dev    #2087    +/-   ##
========================================
  Coverage   82.69%   82.69%            
========================================
  Files         332      333     +1     
  Lines       59700    59710    +10     
  Branches    12267    12090   -177     
========================================
+ Hits        49368    49377     +9     
+ Misses       8928     8924     -4     
- Partials     1404     1409     +5     
Flag Coverage Δ
23.11.6 7.29% <0.00%> (-0.06%) ⬇️
24.11.5 7.33% <0.00%> (-0.02%) ⬇️
25.11.1 7.34% <0.00%> (-0.01%) ⬇️
alpine320 76.74% <53.94%> (-0.08%) ⬇️
fedora42 76.31% <53.94%> (-0.08%) ⬇️
macos-14 82.15% <76.54%> (-0.05%) ⬇️
macos-15 82.14% <76.54%> (-0.05%) ⬇️
mingw32 ?
mingw64 ?
npcap ?
rhel94 76.12% <51.94%> (-0.09%) ⬇️
ubuntu2204 76.13% <51.94%> (-0.08%) ⬇️
ubuntu2204-icpx 59.27% <ø> (-0.03%) ⬇️
ubuntu2404 76.44% <53.33%> (-0.08%) ⬇️
ubuntu2404-arm64 76.42% <53.33%> (-0.08%) ⬇️
ubuntu2604 76.35% <53.94%> (-0.10%) ⬇️
unittest 82.69% <73.52%> (+<0.01%) ⬆️
windows-2022 85.64% <ø> (+0.02%) ⬆️
windows-2025 85.69% <ø> (+0.03%) ⬆️
winpcap 85.69% <ø> (-0.17%) ⬇️
xdp 53.39% <51.94%> (+0.33%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Dimi1010

Dimi1010 commented Mar 24, 2026

Copy link
Copy Markdown
Collaborator Author

Well, this is inconvenient. I reworked the multithreaded test to actually stress test the logger for synchronization issues, and apparently MemPlumber infrastructure starts to seg fault. Possibly because it can't handle 2 threads deallocating at once?

@Dimi1010
Dimi1010 force-pushed the fix/logger-tests branch from 86c632b to 30b43ac Compare May 2, 2026 19:44
@Dimi1010
Dimi1010 force-pushed the fix/logger-tests branch from 30b43ac to 2cd4afd Compare May 2, 2026 19:45
Comment on lines +175 to 192
void printLogThread(int threadId, int numMessages)
{
std::random_device rd;
std::mt19937 simpleRand(rd());
std::uniform_int_distribution<int> dist(1, 5);

std::ostringstream sstream;
sstream << threadId;
std::string threadIdAsString = sstream.str();
for (int i = 0; i < 1000; i++)

for (int i = 0; i < numMessages; i++)
{
pcpp::invokeErrorLog(threadIdAsString);

int sleepTime = dist(simpleRand);
std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
}
}

@Dimi1010 Dimi1010 May 2, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is faulty as it does not test multithreaded calls reliably.

The current implementation does test calling the logger from different threads, but does not reliably perform them simultaneously due to the large sleep intervals. The chance of Thread1 and Thread2 calling the logger at the same time to test for actual sync issues is exceedingly rare.

It is also a large time sink in the CI pipeline, due to the test "faking" work by sleeping a lot.


Originally the PR included fixes for this, but I decided to separate those to keep the PR focused.

@@ -34,66 +35,86 @@ namespace pcpp
class LogPrinter

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converted LogPrinter to an instance to simplify the code as the logger can now take a lambda callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logging tests do not restore original logging executable configuration.

1 participant