forked from OSchip/llvm-project
[libcxx] [test] Make the condvar wait_for tests a bit more understandable. NFC.
This was requested in the review of D99175; rename the "runs" variable to clarify what it means wrt the test, and move updating of it to the main function to clarify its behaviour wrt the two runs further. Differential Revision: https://reviews.llvm.org/D99768
This commit is contained in:
parent
a89fb29398
commit
f8013a35b6
|
@ -33,7 +33,7 @@ std::mutex mut;
|
|||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
bool expect_timeout = false;
|
||||
|
||||
void f()
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ void f()
|
|||
if (d <= milliseconds(0)) break;
|
||||
} while (test2 == 0 && cv.wait_for(lk, d) == std::cv_status::no_timeout);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
if (!expect_timeout)
|
||||
{
|
||||
assert(t1 - t0 < milliseconds(250));
|
||||
assert(test2 != 0);
|
||||
|
@ -61,7 +61,6 @@ void f()
|
|||
assert(t1 - t0 - milliseconds(250) < milliseconds(50));
|
||||
assert(test2 == 0);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
|
@ -80,6 +79,7 @@ int main(int, char**)
|
|||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
expect_timeout = true;
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mut);
|
||||
std::thread t = support::make_test_thread(f);
|
||||
|
|
|
@ -36,7 +36,7 @@ L0 m0;
|
|||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
bool expect_timeout = false;
|
||||
|
||||
void f()
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ void f()
|
|||
if (d <= milliseconds(0)) break;
|
||||
} while (test2 == 0 && cv.wait_for(lk, d) == std::cv_status::no_timeout);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
if (!expect_timeout)
|
||||
{
|
||||
assert(t1 - t0 < milliseconds(250));
|
||||
assert(test2 != 0);
|
||||
|
@ -64,7 +64,6 @@ void f()
|
|||
assert(t1 - t0 - milliseconds(250) < milliseconds(50));
|
||||
assert(test2 == 0);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
|
@ -83,6 +82,7 @@ int main(int, char**)
|
|||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
expect_timeout = true;
|
||||
{
|
||||
L1 lk(m0);
|
||||
std::thread t = support::make_test_thread(f);
|
||||
|
|
Loading…
Reference in New Issue