semaphore_test.cc: add TimedWaitSpuriousWakeupLinux#1037
Conversation
❌ Integration test FAILEDRequested by @dconeybe on commit 69b870d
Add flaky tests to go/fpl-cpp-flake-tracker |
… it is out-of-scope for this PR
app/tests/semaphore_test.cc
Outdated
| 0.20 * firebase::internal::kMillisecondsPerSecond); | ||
| } | ||
|
|
||
| #if SEMAPHORE_LINUX |
There was a problem hiding this comment.
WDYT about just using #ifdef FIREBASE_ANDROID || FIREBASE_LINUX here and above? To me that's clearer, even though it's not the same as the check in semaphore.h.
app/tests/semaphore_test.cc
Outdated
|
|
||
| // Make sure that Semaphore::TimedWait() blocked for the entire timeout, and, | ||
| // specifically, did NOT return early as a result of the SIGUSR1 interruption. | ||
| ASSERT_LT(labs((finish_ms - start_ms) - |
There was a problem hiding this comment.
Can we just use EXPECT_NEAR here?
There was a problem hiding this comment.
Yes, EXPECT_NEAR works perfectly. Done.
app/tests/semaphore_test.cc
Outdated
| // Call Semaphore::TimedWait() and keep track of how long it blocks for. | ||
| firebase::Semaphore sem(0); | ||
| int64_t start_ms = firebase::internal::GetTimestamp(); | ||
| EXPECT_FALSE(sem.TimedWait(2 * firebase::internal::kMillisecondsPerSecond)); |
There was a problem hiding this comment.
2 * firebase::internal::kMillisecondsPerSecond should be in a constant in this function, for clarity
app/tests/semaphore_test.cc
Outdated
| TEST(SemaphoreTest, TimedWaitSpuriousWakeupLinux) { | ||
| // Register a dummy signal handler for SIGUSR1; otherwise, sending SIGUSR1 | ||
| // later on will crash the application. | ||
| signal(SIGUSR1, [](int signum) -> void {}); |
There was a problem hiding this comment.
Does this actually need the trailing return type syntax?
There was a problem hiding this comment.
No it does not. I've removed the trailing return.
app/tests/semaphore_test.cc
Outdated
| // specifically, did NOT return early as a result of the SIGUSR1 interruption. | ||
| ASSERT_LT(labs((finish_ms - start_ms) - | ||
| (2 * firebase::internal::kMillisecondsPerSecond)), | ||
| 0.20 * firebase::internal::kMillisecondsPerSecond); |
There was a problem hiding this comment.
The allowed delta should probably also be in a constant
jonsimantov
left a comment
There was a problem hiding this comment.
Approved with one nit
app/tests/semaphore_test.cc
Outdated
| // Call Semaphore::TimedWait() and keep track of how long it blocks for. | ||
| firebase::Semaphore sem(0); | ||
| auto start_ms = firebase::internal::GetTimestamp(); | ||
| const int timed_wait_timeout = 2 * firebase::internal::kMillisecondsPerSecond; |
There was a problem hiding this comment.
I think the constants should probably follow the kConstantNaming syntax
|
@jonsimantov Please re-approve, as your previous approval was dismissed as being "stale". |
Add a unit test for the Semaphore::TimedWait() spurious wakeup fix in #1021.