-
Notifications
You must be signed in to change notification settings - Fork 122
semaphore_test.cc: add TimedWaitSpuriousWakeupLinux #1037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
@@ -76,6 +88,43 @@ TEST(SemaphoreTest, TimedWait) { | |||
0.20 * firebase::internal::kMillisecondsPerSecond); | |||
} | |||
|
|||
#if SEMAPHORE_LINUX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use EXPECT_NEAR here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 * firebase::internal::kMillisecondsPerSecond should be in a constant in this function, for clarity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this actually need the trailing return type syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The allowed delta should probably also be in a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the constants should probably follow the kConstantNaming syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@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.