Loading tests/dns_metrics_listener/dns_metrics_listener.cpp +5 −3 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ constexpr milliseconds kEventTimeoutMs{5000}; const std::string& prefixString, int32_t /*prefixLength*/) { std::lock_guard lock(mMutex); mUnexpectedNat64PrefixUpdates++; if (netId == mNetId) mNat64Prefix = added ? prefixString : ""; return ::ndk::ScopedAStatus::ok(); } Loading @@ -49,16 +50,17 @@ constexpr milliseconds kEventTimeoutMs{5000}; return ::ndk::ScopedAStatus::ok(); } bool DnsMetricsListener::waitForNat64Prefix(ExpectNat64PrefixStatus status, milliseconds timeout) const { bool DnsMetricsListener::waitForNat64Prefix(ExpectNat64PrefixStatus status, milliseconds timeout) { android::base::Timer t; while (t.duration() < timeout) { { std::lock_guard lock(mMutex); if ((status == EXPECT_FOUND && !mNat64Prefix.empty()) || (status == EXPECT_NOT_FOUND && mNat64Prefix.empty())) (status == EXPECT_NOT_FOUND && mNat64Prefix.empty())) { mUnexpectedNat64PrefixUpdates--; return true; } } std::this_thread::sleep_for(kRetryIntervalMs); } return false; Loading tests/dns_metrics_listener/dns_metrics_listener.h +21 −2 Original line number Diff line number Diff line Loading @@ -51,8 +51,14 @@ class DnsMetricsListener : public BaseMetricsListener { bool validated) override; // Wait for expected NAT64 prefix status until timeout. bool waitForNat64Prefix(ExpectNat64PrefixStatus status, std::chrono::milliseconds timeout) const; bool waitForNat64Prefix(ExpectNat64PrefixStatus status, std::chrono::milliseconds timeout) EXCLUDES(mMutex); // Returns the number of updates to the NAT64 prefix that have not yet been waited for. int getUnexpectedNat64PrefixUpdates() const EXCLUDES(mMutex) { std::lock_guard lock(mMutex); return mUnexpectedNat64PrefixUpdates; } // Wait for the expected private DNS validation result until timeout. bool waitForPrivateDnsValidation(const std::string& serverAddr, const bool validated); Loading @@ -64,6 +70,12 @@ class DnsMetricsListener : public BaseMetricsListener { return mValidationRecords.find({mNetId, serverAddr}) != mValidationRecords.end(); } void reset() EXCLUDES(mMutex) { std::lock_guard lock(mMutex); mUnexpectedNat64PrefixUpdates = 0; mValidationRecords.clear(); } private: typedef std::pair<int32_t, std::string> ServerKey; Loading @@ -77,6 +89,13 @@ class DnsMetricsListener : public BaseMetricsListener { // The NAT64 prefix of the network |mNetId|. It is updated by the event onNat64PrefixEvent(). std::string mNat64Prefix GUARDED_BY(mMutex); // The number of updates to the NAT64 prefix of network |mNetId| that have not yet been waited // for. Increases by 1 every time onNat64PrefixEvent is called, and decreases by 1 every time // waitForNat64Prefix returns true. // This allows tests to check that no unexpected events have been received without having to // resort to timeouts that make the tests slower and flakier. int mUnexpectedNat64PrefixUpdates GUARDED_BY(mMutex); // Used to store the data from onPrivateDnsValidationEvent. std::map<ServerKey, bool> mValidationRecords GUARDED_BY(mMutex); Loading tests/resolv_integration_test.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -185,7 +185,11 @@ class ResolverTest : public ::testing::Test { static void TearDownTestSuite() { AIBinder_DeathRecipient_delete(sResolvDeathRecipient); } protected: void SetUp() { mDnsClient.SetUp(); } void SetUp() { mDnsClient.SetUp(); sDnsMetricsListener->reset(); } void TearDown() { // Ensure the dump works at the end of each test. DumpResolverService(); Loading Loading @@ -3816,6 +3820,8 @@ TEST_F(ResolverTest, SetAndClearNat64Prefix) { EXPECT_TRUE(resolvService->stopPrefix64Discovery(TEST_NETID).isOk()); EXPECT_TRUE(WaitForNat64Prefix(EXPECT_NOT_FOUND)); EXPECT_EQ(0, sDnsMetricsListener->getUnexpectedNat64PrefixUpdates()); } namespace { Loading Loading
tests/dns_metrics_listener/dns_metrics_listener.cpp +5 −3 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ constexpr milliseconds kEventTimeoutMs{5000}; const std::string& prefixString, int32_t /*prefixLength*/) { std::lock_guard lock(mMutex); mUnexpectedNat64PrefixUpdates++; if (netId == mNetId) mNat64Prefix = added ? prefixString : ""; return ::ndk::ScopedAStatus::ok(); } Loading @@ -49,16 +50,17 @@ constexpr milliseconds kEventTimeoutMs{5000}; return ::ndk::ScopedAStatus::ok(); } bool DnsMetricsListener::waitForNat64Prefix(ExpectNat64PrefixStatus status, milliseconds timeout) const { bool DnsMetricsListener::waitForNat64Prefix(ExpectNat64PrefixStatus status, milliseconds timeout) { android::base::Timer t; while (t.duration() < timeout) { { std::lock_guard lock(mMutex); if ((status == EXPECT_FOUND && !mNat64Prefix.empty()) || (status == EXPECT_NOT_FOUND && mNat64Prefix.empty())) (status == EXPECT_NOT_FOUND && mNat64Prefix.empty())) { mUnexpectedNat64PrefixUpdates--; return true; } } std::this_thread::sleep_for(kRetryIntervalMs); } return false; Loading
tests/dns_metrics_listener/dns_metrics_listener.h +21 −2 Original line number Diff line number Diff line Loading @@ -51,8 +51,14 @@ class DnsMetricsListener : public BaseMetricsListener { bool validated) override; // Wait for expected NAT64 prefix status until timeout. bool waitForNat64Prefix(ExpectNat64PrefixStatus status, std::chrono::milliseconds timeout) const; bool waitForNat64Prefix(ExpectNat64PrefixStatus status, std::chrono::milliseconds timeout) EXCLUDES(mMutex); // Returns the number of updates to the NAT64 prefix that have not yet been waited for. int getUnexpectedNat64PrefixUpdates() const EXCLUDES(mMutex) { std::lock_guard lock(mMutex); return mUnexpectedNat64PrefixUpdates; } // Wait for the expected private DNS validation result until timeout. bool waitForPrivateDnsValidation(const std::string& serverAddr, const bool validated); Loading @@ -64,6 +70,12 @@ class DnsMetricsListener : public BaseMetricsListener { return mValidationRecords.find({mNetId, serverAddr}) != mValidationRecords.end(); } void reset() EXCLUDES(mMutex) { std::lock_guard lock(mMutex); mUnexpectedNat64PrefixUpdates = 0; mValidationRecords.clear(); } private: typedef std::pair<int32_t, std::string> ServerKey; Loading @@ -77,6 +89,13 @@ class DnsMetricsListener : public BaseMetricsListener { // The NAT64 prefix of the network |mNetId|. It is updated by the event onNat64PrefixEvent(). std::string mNat64Prefix GUARDED_BY(mMutex); // The number of updates to the NAT64 prefix of network |mNetId| that have not yet been waited // for. Increases by 1 every time onNat64PrefixEvent is called, and decreases by 1 every time // waitForNat64Prefix returns true. // This allows tests to check that no unexpected events have been received without having to // resort to timeouts that make the tests slower and flakier. int mUnexpectedNat64PrefixUpdates GUARDED_BY(mMutex); // Used to store the data from onPrivateDnsValidationEvent. std::map<ServerKey, bool> mValidationRecords GUARDED_BY(mMutex); Loading
tests/resolv_integration_test.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -185,7 +185,11 @@ class ResolverTest : public ::testing::Test { static void TearDownTestSuite() { AIBinder_DeathRecipient_delete(sResolvDeathRecipient); } protected: void SetUp() { mDnsClient.SetUp(); } void SetUp() { mDnsClient.SetUp(); sDnsMetricsListener->reset(); } void TearDown() { // Ensure the dump works at the end of each test. DumpResolverService(); Loading Loading @@ -3816,6 +3820,8 @@ TEST_F(ResolverTest, SetAndClearNat64Prefix) { EXPECT_TRUE(resolvService->stopPrefix64Discovery(TEST_NETID).isOk()); EXPECT_TRUE(WaitForNat64Prefix(EXPECT_NOT_FOUND)); EXPECT_EQ(0, sDnsMetricsListener->getUnexpectedNat64PrefixUpdates()); } namespace { Loading