Skip to content

Commit e40e439

Browse files
Merge pull request #987 from openzim/fixing_issue986
More stable Log.concurrencyOrchestration unittest
2 parents 8690640 + 3f57548 commit e40e439

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

test/log.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,27 @@ TEST(Log, inMemLogInANamedThread) {
7676

7777
#include <chrono>
7878

79-
TEST(Log, concurrencyOrchestration) {
79+
void millisleep(unsigned milliseconds) {
80+
// Pause the current thread for a given number of milliseconds
81+
// in multiple 1ms shots. This gives the scheduler higher probability
82+
// of waking up the concurrent thread at the right time under high load.
8083
using namespace std::chrono_literals;
8184

85+
for ( unsigned i = 0; i < milliseconds; ++i )
86+
std::this_thread::sleep_for(1ms);
87+
}
88+
89+
TEST(Log, concurrencyOrchestration) {
8290
const auto oddFlow = [](){
83-
std::this_thread::sleep_for(100ms);
91+
millisleep(10);
8492
log_debug("Humpty Dumpty sat on a wall.");
85-
std::this_thread::sleep_for(100ms);
93+
millisleep(10);
8694
log_debug("All the king's horses and all the king's men");
8795
};
8896

8997
const auto evenFlow = [](){
9098
log_debug("Humpty Dumpty had a great fall.");
91-
std::this_thread::sleep_for(150ms);
99+
millisleep(15);
92100
log_debug("Couldn't put Humpty together again.");
93101
};
94102

0 commit comments

Comments
 (0)