reduce wait time in test

This commit is contained in:
krunal 2023-12-05 15:38:18 +05:30
parent cc83b6697e
commit 4c1e487398
3 changed files with 6 additions and 11 deletions

View File

@ -216,5 +216,5 @@ public:
nlohmann::json get_query_hits_counts();
void checkEventsExpiry();
void checkEventsExpiry(uint64_t events_ttl_interval=2592000000000); //30days default
};

View File

@ -10,11 +10,6 @@
LRU::Cache<std::string, event_cache_t> events_cache;
#define CLICK_EVENTS_RATE_LIMIT_SEC 60
#define CLICK_EVENTS_RATE_LIMIT_COUNT 5
#ifdef TEST_BUILD
#define EVENTS_TTL_INTERVAL_US 30000000 //30sec
#else
#define EVENTS_TTL_INTERVAL_US 2592000000000 //30days
#endif
Option<bool> AnalyticsManager::create_rule(nlohmann::json& payload, bool upsert, bool write_to_disk) {
/*
@ -614,7 +609,7 @@ void AnalyticsManager::resetRateLimit() {
events_cache.clear();
}
void AnalyticsManager::checkEventsExpiry() {
void AnalyticsManager::checkEventsExpiry(uint64_t events_ttl_interval) {
if (analytics_store) {
//LOG(INFO) << "checking for events expiry";
@ -622,7 +617,7 @@ void AnalyticsManager::checkEventsExpiry() {
auto now_ts_useconds = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
auto ts_ttl_useconds = now_ts_useconds - EVENTS_TTL_INTERVAL_US;
auto ts_ttl_useconds = now_ts_useconds - events_ttl_interval;
const std::string click_events_prefix = std::string(CLICK_EVENT) + "_";
const std::string query_hits_prefix = std::string(QUERY_HITS_COUNT) + "_";

View File

@ -552,9 +552,9 @@ TEST_F(AnalyticsManagerTest, EventsExpiry) {
ASSERT_EQ(13, resp[1]["user_id"]);
LOG(INFO) << "waiting for TTL to pass";
sleep(35);//wait till ttl passes which is set to 30 seconds
sleep(1);//wait till ttl passes
analyticsManager.checkEventsExpiry();
analyticsManager.checkEventsExpiry(1000000); //1 second
resp = analyticsManager.get_click_events();
ASSERT_EQ(0, resp.size());
@ -580,7 +580,7 @@ TEST_F(AnalyticsManagerTest, EventsExpiry) {
ASSERT_EQ(124, resp[0]["hits_count"]);
//now old click events will be deleted on checking expiry but query hits events will be remaining
analyticsManager.checkEventsExpiry();
analyticsManager.checkEventsExpiry(1000000); //1 second
resp = analyticsManager.get_click_events();
ASSERT_EQ(0, resp.size());