Skip to content

Commit

Permalink
Add regression testing for 'stats_mysql_query_digest' timestamps
Browse files Browse the repository at this point in the history
- Added regression testing for timestamps 'first_seen' and 'last_seen'.
- Make the test idempotent by cleaning up 'stats_mysql_query_digest'.
  • Loading branch information
JavierJF committed Jul 11, 2023
1 parent 9e258b8 commit affc7a1
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/tap/tests/test_digest_umap_aux-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}

plan(1 + DUMMY_QUERIES.size() * 3); // always specify the number of tests that are going to be performed
plan(1 + DUMMY_QUERIES.size() * 5); // always specify the number of tests that are going to be performed

MYSQL *proxy_admin = mysql_init(NULL);
if (!mysql_real_connect(proxy_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
Expand All @@ -199,6 +199,8 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}

time_t init_time = time(NULL);

MYSQL_RES *res = NULL;
for (const auto &query : DUMMY_QUERIES) {
diag("Running: %s", query);
Expand Down Expand Up @@ -243,6 +245,8 @@ int main(int argc, char** argv) {
);

vector<digest_stats> ds_vector_after = get_digest_stats(proxy_admin);
time_t final_time = time(NULL);

for (int i = 0; i < DUMMY_QUERIES.size(); i++) {
ok(
ds_vector_before[i].hostgroup == ds_vector_after[i].hostgroup &&
Expand Down Expand Up @@ -285,7 +289,24 @@ int main(int argc, char** argv) {
ds_vector_before[i].last_seen, ds_vector_after[i].last_seen,
ds_vector_before[i].sum_time, ds_vector_after[i].sum_time
);

uint64_t bf_first_seen = ds_vector_before[i].first_seen;
ok(
init_time - 1 <= bf_first_seen && init_time + 1 >= bf_first_seen,
"'first_seen' within required time range - min: %ld, max: %ld, first_seen: %ld",
init_time - 1, init_time + 1, bf_first_seen
);

uint64_t bf_last_seen = ds_vector_before[i].last_seen;
ok(
init_time <= bf_last_seen && final_time >= bf_last_seen,
"'last_seen' within required time range - min: %ld, max: %ld, last_seen: %ld",
init_time, final_time, bf_last_seen
);
}

mysql_query(proxy_admin, "TRUNCATE TABLE stats.stats_mysql_query_digest");
mysql_close(proxy_admin);

return exit_status();
}

0 comments on commit affc7a1

Please sign in to comment.