From cd4f178163bfa164496597851c7185f50d5c74e8 Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Thu, 9 Jul 2020 15:33:48 -0400 Subject: [PATCH 1/2] added a grace period of 10s for macos listener verification in unit tests. --- auth/tests/desktop/test_utils.cc | 18 ++++++++++++++++-- auth/tests/desktop/test_utils.h | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/auth/tests/desktop/test_utils.cc b/auth/tests/desktop/test_utils.cc index de86beed5a..ec448b10b9 100644 --- a/auth/tests/desktop/test_utils.cc +++ b/auth/tests/desktop/test_utils.cc @@ -28,13 +28,27 @@ void ListenerChangeCounter::ExpectChanges(const int num) { expected_changes_ = num; } void ListenerChangeCounter::VerifyAndReset() { - Verify(); + int timeout_value = -1; +#ifdef __APPLE__ + timeout_value = 10000; +#endif + Verify(timeout_value); expected_changes_ = -1; actual_changes_ = 0; } -void ListenerChangeCounter::Verify() { +void ListenerChangeCounter::Verify(int timeout) { if (expected_changes_ != -1) { + if (timeout >= 0) { + int elapsed_time = 0; + while( elapsed_time <= timeout ) { + if(expected_changes_ == actual_changes_) { + break; + } + firebase::internal::Sleep(100); + elapsed_time += 100; // only estimating elapsed time to simplfy portability. + } + } EXPECT_EQ(expected_changes_, actual_changes_); } } diff --git a/auth/tests/desktop/test_utils.h b/auth/tests/desktop/test_utils.h index 97d0379de2..afb8962bba 100644 --- a/auth/tests/desktop/test_utils.h +++ b/auth/tests/desktop/test_utils.h @@ -45,9 +45,9 @@ class ListenerChangeCounter { int actual_changes_; private: - void Verify(); + void Verify(int timeout = -1); - int expected_changes_; + volatile int expected_changes_; }; } // namespace detail From 8fc38640b9a46eea7bd1d1ab39412345e2ebf1e8 Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Thu, 9 Jul 2020 16:11:58 -0400 Subject: [PATCH 2/2] output sleep progression --- auth/tests/desktop/test_utils.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/auth/tests/desktop/test_utils.cc b/auth/tests/desktop/test_utils.cc index ec448b10b9..510629b1b0 100644 --- a/auth/tests/desktop/test_utils.cc +++ b/auth/tests/desktop/test_utils.cc @@ -39,15 +39,17 @@ void ListenerChangeCounter::VerifyAndReset() { void ListenerChangeCounter::Verify(int timeout) { if (expected_changes_ != -1) { - if (timeout >= 0) { + if (timeout >= 0 && expected_changes_ != actual_changes_) { int elapsed_time = 0; while( elapsed_time <= timeout ) { + printf("."); + firebase::internal::Sleep(100); + elapsed_time += 100; // only estimating elapsed time to simplfy portability. if(expected_changes_ == actual_changes_) { break; } - firebase::internal::Sleep(100); - elapsed_time += 100; // only estimating elapsed time to simplfy portability. } + printf("\n"); } EXPECT_EQ(expected_changes_, actual_changes_); }