Skip to content

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

Merged
merged 10 commits into from
Jul 26, 2022

Conversation

dconeybe
Copy link
Contributor

Add a unit test for the Semaphore::TimedWait() spurious wakeup fix in #1021.

@dconeybe dconeybe added the skip-release-notes Skip release notes check label Jul 20, 2022
@dconeybe dconeybe self-assigned this Jul 20, 2022
@dconeybe dconeybe added the tests-requested: quick Trigger a quick set of integration tests. label Jul 20, 2022
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. and removed tests-requested: quick Trigger a quick set of integration tests. labels Jul 20, 2022
@github-actions
Copy link

github-actions bot commented Jul 20, 2022

❌  Integration test FAILED

Requested by @dconeybe on commit 69b870d
Last updated: Tue Jul 26 13:40 PDT 2022
View integration test log & download artifacts

Failures Configs
firestore [TEST] [FAILURE] [iOS] [macos] [1/2 ios_device: simulator_target]
(1 failed tests)  NumericTransformsTest.CreateDocumentWithIncrement
[TEST] [FLAKINESS] [Android] [1/3 os: windows] [1/2 android_device: android_target]
(1 failed tests)  ServerTimestampTest.TestServerTimestampsUsesPreviousValueFromLocalMutation
gma [TEST] [FLAKINESS] [iOS] [macos] [1/2 ios_device: ios_target]
(1 failed tests)  FirebaseGmaTest.TestRewardedAdStress
storage [TEST] [FLAKINESS] [iOS] [macos] [1/2 ios_device: ios_target]
(1 failed tests)  FirebaseStorageTest.TestWriteAndReadCustomContentType

Add flaky tests to go/fpl-cpp-flake-tracker

@dconeybe dconeybe removed the tests: in-progress This PR's integration tests are in progress. label Jul 20, 2022
@dconeybe dconeybe requested a review from jonsimantov July 20, 2022 19:08
@dconeybe dconeybe added the tests-requested: quick Trigger a quick set of integration tests. label Jul 20, 2022
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. tests: failed This PR's integration tests failed. and removed tests-requested: quick Trigger a quick set of integration tests. labels Jul 20, 2022
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Jul 20, 2022
@github-actions github-actions bot added the tests: succeeded This PR's integration tests succeeded. label Jul 21, 2022
@dconeybe dconeybe removed the tests: failed This PR's integration tests failed. label Jul 21, 2022
@@ -76,6 +88,43 @@ TEST(SemaphoreTest, TimedWait) {
0.20 * firebase::internal::kMillisecondsPerSecond);
}

#if SEMAPHORE_LINUX
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


// 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) -
Copy link
Contributor

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?

Copy link
Contributor Author

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.

// 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));
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

TEST(SemaphoreTest, TimedWaitSpuriousWakeupLinux) {
// Register a dummy signal handler for SIGUSR1; otherwise, sending SIGUSR1
// later on will crash the application.
signal(SIGUSR1, [](int signum) -> void {});
Copy link
Contributor

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?

Copy link
Contributor Author

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.

// 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);
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dconeybe dconeybe removed the tests: succeeded This PR's integration tests succeeded. label Jul 24, 2022
@dconeybe dconeybe requested a review from jonsimantov July 25, 2022 14:54
@dconeybe dconeybe added the tests-requested: quick Trigger a quick set of integration tests. label Jul 25, 2022
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. tests: failed This PR's integration tests failed. and removed tests-requested: quick Trigger a quick set of integration tests. labels Jul 25, 2022
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Jul 25, 2022
@github-actions github-actions bot added the tests: succeeded This PR's integration tests succeeded. label Jul 25, 2022
Copy link
Contributor

@jonsimantov jonsimantov left a 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

// 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;
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dconeybe dconeybe removed tests: succeeded This PR's integration tests succeeded. tests: failed This PR's integration tests failed. labels Jul 26, 2022
@dconeybe dconeybe requested a review from jonsimantov July 26, 2022 04:13
@dconeybe
Copy link
Contributor Author

@jonsimantov Please re-approve, as your previous approval was dismissed as being "stale".

@dconeybe dconeybe added the tests-requested: quick Trigger a quick set of integration tests. label Jul 26, 2022
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. tests: succeeded This PR's integration tests succeeded. and removed tests-requested: quick Trigger a quick set of integration tests. labels Jul 26, 2022
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Jul 26, 2022
@dconeybe dconeybe merged commit 69b870d into main Jul 26, 2022
@dconeybe dconeybe deleted the dconeybe/SemaphoreTimedWaitUnitTest branch July 26, 2022 17:57
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. tests: failed This PR's integration tests failed. and removed tests: succeeded This PR's integration tests succeeded. labels Jul 26, 2022
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Jul 26, 2022
@firebase firebase locked and limited conversation to collaborators Aug 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
skip-release-notes Skip release notes check tests: failed This PR's integration tests failed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants