Skip to content

Commit 42e2aac

Browse files
[UTest] Fix #213: Increase delays in async test.
Increase delays in an asynchronous / multi-threaded test to reduce the chance of odd scheduling. The test randomly and infrequently failed before, as the scheduling could be different than expected. Our delays were simply not long enough. `fork()` can take a considerable amount of time... This test **did not fail** because of data races or other synchronization issues.
1 parent e745efc commit 42e2aac

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

unittest/util/reader_writer_lock_test.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,37 +41,37 @@ TEST_CASE("reader_writer_mutex/reader_writer_lock/3_readers_2_writers", "[core][
4141
lock.lock_write();
4242
M_insist(lock.owns_write_lock());
4343
shared_value += delta;
44-
std::this_thread::sleep_for(5ms);
44+
std::this_thread::sleep_for(50ms);
4545
};
4646

4747
auto read = [&mutex, &shared_value](int &dest) {
4848
reader_writer_lock lock{mutex};
4949
lock.lock_read();
5050
M_insist(lock.owns_read_lock());
5151
dest = shared_value;
52-
std::this_thread::sleep_for(5ms);
52+
std::this_thread::sleep_for(50ms);
5353
};
5454

55-
/* Spawn first reader, taking 5ms. */
55+
/* Spawn first reader, taking 50ms. */
5656
std::thread tr1{read, std::ref(r1)};
57-
std::this_thread::sleep_for(1ms);
57+
std::this_thread::sleep_for(10ms);
5858

59-
/* Spawn first writer, taking 5ms. It is blocked by the first reader. */
59+
/* Spawn first writer, taking 50ms. It is blocked by the first reader. */
6060
std::thread tw1{write, 1};
61-
std::this_thread::sleep_for(1ms);
61+
std::this_thread::sleep_for(10ms);
6262

6363
/* Spawn second reader. The first reader should still be active while the first writer is still blocked.
6464
* Therefore, the newly spawned second reader should wait for the writer to finish. */
6565
std::thread tr2{read, std::ref(r2)};
66-
std::this_thread::sleep_for(1ms);
66+
std::this_thread::sleep_for(10ms);
6767

6868
/* Spawn second writer. */
6969
std::thread tw2{write, 2};
70-
std::this_thread::sleep_for(1ms);
70+
std::this_thread::sleep_for(10ms);
7171

7272
/* Spawn third reader. */
7373
std::thread tr3{read, std::ref(r3)};
74-
std::this_thread::sleep_for(1ms);
74+
std::this_thread::sleep_for(10ms);
7575

7676
tr1.join();
7777
tr2.join();
@@ -93,36 +93,36 @@ TEST_CASE("reader_writer_mutex/read_lock_write_lock/3_readers_2_writers", "[core
9393
write_lock lock{mutex};
9494
M_insist(lock.owns_lock());
9595
shared_value += delta;
96-
std::this_thread::sleep_for(5ms);
96+
std::this_thread::sleep_for(50ms);
9797
};
9898

9999
auto read = [&mutex, &shared_value](int &dest) {
100100
read_lock lock{mutex};
101101
M_insist(lock.owns_lock());
102102
dest = shared_value;
103-
std::this_thread::sleep_for(5ms);
103+
std::this_thread::sleep_for(50ms);
104104
};
105105

106-
/* Spawn first reader, taking 5ms. */
106+
/* Spawn first reader, taking 50ms. */
107107
std::thread tr1{read, std::ref(r1)};
108-
std::this_thread::sleep_for(1ms);
108+
std::this_thread::sleep_for(10ms);
109109

110-
/* Spawn first writer, taking 5ms. It is blocked by the first reader. */
110+
/* Spawn first writer, taking 50ms. It is blocked by the first reader. */
111111
std::thread tw1{write, 1};
112-
std::this_thread::sleep_for(1ms);
112+
std::this_thread::sleep_for(10ms);
113113

114114
/* Spawn second reader. The first reader should still be active while the first writer is still blocked.
115115
* Therefore, the newly spawned second reader should wait for the writer to finish. */
116116
std::thread tr2{read, std::ref(r2)};
117-
std::this_thread::sleep_for(1ms);
117+
std::this_thread::sleep_for(10ms);
118118

119119
/* Spawn second writer. */
120120
std::thread tw2{write, 2};
121-
std::this_thread::sleep_for(1ms);
121+
std::this_thread::sleep_for(10ms);
122122

123123
/* Spawn third reader. */
124124
std::thread tr3{read, std::ref(r3)};
125-
std::this_thread::sleep_for(1ms);
125+
std::this_thread::sleep_for(10ms);
126126

127127
tr1.join();
128128
tr2.join();

0 commit comments

Comments
 (0)