diff options
author | Mike Yu <yumike@google.com> | 2019-10-31 16:12:23 +0800 |
---|---|---|
committer | Mike Yu <yumike@google.com> | 2019-12-11 22:31:45 +0800 |
commit | 39df0b13bb000abfbc9fbb01edacd54f4fc421c9 (patch) | |
tree | 5c46857705be0841cc4b895cfa8e3994a2cae8f8 /DnsQueryLog.h | |
parent | 939e3690aeb0142679678313a74bf024cfba7129 (diff) | |
download | DnsResolver-39df0b13bb000abfbc9fbb01edacd54f4fc421c9.tar.gz |
Add unit tests for DnsQueryLog
Ensure the basic functions of DnsQueryLog work as expected.
Bug: 139040977
Test: cd packages/modules/DnsResolver && atest
Change-Id: I6b318beeed7ff5942e8d08474c354e48ebdac936
Diffstat (limited to 'DnsQueryLog.h')
-rw-r--r-- | DnsQueryLog.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/DnsQueryLog.h b/DnsQueryLog.h index a3190471..c19f8db3 100644 --- a/DnsQueryLog.h +++ b/DnsQueryLog.h @@ -49,18 +49,25 @@ class DnsQueryLog { const int timeTaken; }; + // Allow the tests to set the capacity and the validaty time in milliseconds. + DnsQueryLog(size_t size = kDefaultLogSize, + std::chrono::milliseconds time = kDefaultValidityMinutes) + : mCapacity(size), mValidityTimeMs(time) {} + void push(Record&& record) EXCLUDES(mLock); void dump(netdutils::DumpWriter& dw) const EXCLUDES(mLock); private: mutable std::mutex mLock; std::deque<Record> mQueue GUARDED_BY(mLock); + const size_t mCapacity; + const std::chrono::milliseconds mValidityTimeMs; // The capacity of the circular buffer. - static constexpr size_t kLogSize = 200; + static constexpr size_t kDefaultLogSize = 200; - // Limit to dump the queries within last |kValidityMinutes| minutes. - static constexpr std::chrono::minutes kValidityMinutes{60}; + // Limit to dump the queries within last |kDefaultValidityMinutes| minutes. + static constexpr std::chrono::minutes kDefaultValidityMinutes{60}; }; } // namespace android::net |