summaryrefslogtreecommitdiffstats
path: root/daemon/unit_test.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:20:02 +0000
commit58daab21cd043e1dc37024a7f99b396788372918 (patch)
tree96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /daemon/unit_test.c
parentReleasing debian version 1.43.2-1. (diff)
downloadnetdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz
netdata-58daab21cd043e1dc37024a7f99b396788372918.zip
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'daemon/unit_test.c')
-rw-r--r--daemon/unit_test.c95
1 files changed, 50 insertions, 45 deletions
diff --git a/daemon/unit_test.c b/daemon/unit_test.c
index b8d22931..149bbec0 100644
--- a/daemon/unit_test.c
+++ b/daemon/unit_test.c
@@ -97,7 +97,7 @@ static int check_number_printing(void) {
int i, failed = 0;
for(i = 0; values[i].correct ; i++) {
print_netdata_double(netdata, values[i].n);
- snprintfz(system, 512, "%0.12" NETDATA_DOUBLE_MODIFIER, (NETDATA_DOUBLE)values[i].n);
+ snprintfz(system, sizeof(system) - 1, "%0.12" NETDATA_DOUBLE_MODIFIER, (NETDATA_DOUBLE)values[i].n);
int ok = 1;
if(strcmp(netdata, values[i].correct) != 0) {
@@ -319,7 +319,7 @@ void benchmark_storage_number(int loop, int multiplier) {
for(i = 0; i < loop ;i++) {
n *= multiplier;
if(n > storage_number_positive_max) n = storage_number_positive_min;
- snprintfz(buffer, 100, NETDATA_DOUBLE_FORMAT, n);
+ snprintfz(buffer, sizeof(buffer) - 1, NETDATA_DOUBLE_FORMAT, n);
}
}
@@ -507,7 +507,7 @@ int unit_test_buffer() {
const char *fmt = "string1: %s\nstring2: %s\nstring3: %s\nstring4: %s";
buffer_sprintf(wb, fmt, string, string, string, string);
- snprintfz(final, 9000, fmt, string, string, string, string);
+ snprintfz(final, sizeof(final) - 1, fmt, string, string, string, string);
const char *s = buffer_tostring(wb);
@@ -1272,7 +1272,7 @@ int run_test(struct test *test)
default_rrd_update_every = test->update_every;
char name[101];
- snprintfz(name, 100, "unittest-%s", test->name);
+ snprintfz(name, sizeof(name) - 1, "unittest-%s", test->name);
// create the chart
RRDSET *st = rrdset_create_localhost("netdata", name, name, "netdata", NULL, "Unit Testing", "a value", "unittest", NULL, 1
@@ -1534,7 +1534,7 @@ int unit_test(long delay, long shift)
repeat++;
char name[101];
- snprintfz(name, 100, "unittest-%d-%ld-%ld", repeat, delay, shift);
+ snprintfz(name, sizeof(name) - 1, "unittest-%d-%ld-%ld", repeat, delay, shift);
//debug_flags = 0xffffffff;
default_rrd_memory_mode = RRD_MEMORY_MODE_ALLOC;
@@ -1681,13 +1681,6 @@ int test_sqlite(void) {
rc = sqlite3_exec_monitored(db_meta, buffer_tostring(sql), 0, 0, NULL);
if (rc != SQLITE_OK)
goto error;
- buffer_flush(sql);
-
- buffer_sprintf(sql, INDEX_ACLK_ALERT, uuid_str, uuid_str);
- rc = sqlite3_exec_monitored(db_meta, buffer_tostring(sql), 0, 0, NULL);
- if (rc != SQLITE_OK)
- goto error;
- buffer_flush(sql);
buffer_free(sql);
fprintf(stderr,"SQLite is OK\n");
@@ -1831,30 +1824,29 @@ static RRDHOST *dbengine_rrdhost_find_or_create(char *name)
/* We don't want to drop metrics when generating load, we prefer to block data generation itself */
return rrdhost_find_or_create(
- name
- , name
- , name
- , os_type
- , netdata_configured_timezone
- , netdata_configured_abbrev_timezone
- , netdata_configured_utc_offset
- , ""
- , program_name
- , program_version
- , default_rrd_update_every
- , default_rrd_history_entries
- , RRD_MEMORY_MODE_DBENGINE
- , default_health_enabled
- , default_rrdpush_enabled
- , default_rrdpush_destination
- , default_rrdpush_api_key
- , default_rrdpush_send_charts_matching
- , default_rrdpush_enable_replication
- , default_rrdpush_seconds_to_replicate
- , default_rrdpush_replication_step
- , NULL
- , 0
- );
+ name,
+ name,
+ name,
+ os_type,
+ netdata_configured_timezone,
+ netdata_configured_abbrev_timezone,
+ netdata_configured_utc_offset,
+ "",
+ program_name,
+ program_version,
+ default_rrd_update_every,
+ default_rrd_history_entries,
+ RRD_MEMORY_MODE_DBENGINE,
+ default_health_enabled,
+ default_rrdpush_enabled,
+ default_rrdpush_destination,
+ default_rrdpush_api_key,
+ default_rrdpush_send_charts_matching,
+ default_rrdpush_enable_replication,
+ default_rrdpush_seconds_to_replicate,
+ default_rrdpush_replication_step,
+ NULL,
+ 0);
}
// constants for test_dbengine
@@ -1878,7 +1870,7 @@ static void test_dbengine_create_charts(RRDHOST *host, RRDSET *st[CHARTS], RRDDI
char name[101];
for (i = 0 ; i < CHARTS ; ++i) {
- snprintfz(name, 100, "dbengine-chart-%d", i);
+ snprintfz(name, sizeof(name) - 1, "dbengine-chart-%d", i);
// create the chart
st[i] = rrdset_create(host, "netdata", name, name, "netdata", NULL, "Unit Testing", "a value", "unittest",
@@ -1886,7 +1878,7 @@ static void test_dbengine_create_charts(RRDHOST *host, RRDSET *st[CHARTS], RRDDI
rrdset_flag_set(st[i], RRDSET_FLAG_DEBUG);
rrdset_flag_set(st[i], RRDSET_FLAG_STORE_FIRST);
for (j = 0 ; j < DIMS ; ++j) {
- snprintfz(name, 100, "dim-%d", j);
+ snprintfz(name, sizeof(name) - 1, "dim-%d", j);
rd[i][j] = rrddim_add(st[i], name, NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
}
@@ -2108,6 +2100,14 @@ static int test_dbengine_check_rrdr(RRDSET *st[CHARTS], RRDDIM *rd[CHARTS][DIMS]
return errors + value_errors + time_errors;
}
+void test_dbengine_charts_and_dims_are_not_collected(RRDSET *st[CHARTS], RRDDIM *rd[CHARTS][DIMS]) {
+ for(int c = 0; c < CHARTS ; c++) {
+ st[c]->rrdcontexts.collected = false;
+ for(int d = 0; d < DIMS ; d++)
+ rd[c][d]->rrdcontexts.collected = false;
+ }
+}
+
int test_dbengine(void)
{
fprintf(stderr, "%s() running...\n", __FUNCTION__ );
@@ -2117,7 +2117,7 @@ int test_dbengine(void)
RRDDIM *rd[CHARTS][DIMS];
time_t time_start[REGIONS], time_end[REGIONS];
- error_log_limit_unlimited();
+ nd_log_limits_unlimited();
fprintf(stderr, "\nRunning DB-engine test\n");
default_rrd_memory_mode = RRD_MEMORY_MODE_DBENGINE;
@@ -2135,6 +2135,7 @@ int test_dbengine(void)
time_end[current_region] = test_dbengine_create_metrics(st,rd, current_region, time_start[current_region]);
errors += test_dbengine_check_metrics(st, rd, current_region, time_start[current_region]);
+ test_dbengine_charts_and_dims_are_not_collected(st, rd);
current_region = 1; //this is the second region of data
update_every = REGION_UPDATE_EVERY[current_region]; // set data collection frequency to 3 seconds
@@ -2152,6 +2153,7 @@ int test_dbengine(void)
time_end[current_region] = test_dbengine_create_metrics(st,rd, current_region, time_start[current_region]);
errors += test_dbengine_check_metrics(st, rd, current_region, time_start[current_region]);
+ test_dbengine_charts_and_dims_are_not_collected(st, rd);
current_region = 2; //this is the third region of data
update_every = REGION_UPDATE_EVERY[current_region]; // set data collection frequency to 1 seconds
@@ -2169,6 +2171,7 @@ int test_dbengine(void)
time_end[current_region] = test_dbengine_create_metrics(st,rd, current_region, time_start[current_region]);
errors += test_dbengine_check_metrics(st, rd, current_region, time_start[current_region]);
+ test_dbengine_charts_and_dims_are_not_collected(st, rd);
for (current_region = 0 ; current_region < REGIONS ; ++current_region) {
errors += test_dbengine_check_rrdr(st, rd, current_region, time_start[current_region], time_end[current_region]);
@@ -2237,6 +2240,7 @@ int test_dbengine(void)
rrdeng_prepare_exit((struct rrdengine_instance *)host->db[0].instance);
rrdhost_delete_charts(host);
rrdeng_exit((struct rrdengine_instance *)host->db[0].instance);
+ rrdeng_enq_cmd(NULL, RRDENG_OPCODE_SHUTDOWN_EVLOOP, NULL, NULL, STORAGE_PRIORITY_BEST_EFFORT, NULL, NULL);
rrd_unlock();
return errors + value_errors + time_errors;
@@ -2343,7 +2347,7 @@ void generate_dbengine_dataset(unsigned history_seconds)
(1024 * 1024);
default_rrdeng_disk_quota_mb -= default_rrdeng_disk_quota_mb * EXPECTED_COMPRESSION_RATIO / 100;
- error_log_limit_unlimited();
+ nd_log_limits_unlimited();
fprintf(stderr, "Initializing localhost with hostname 'dbengine-dataset'");
host = dbengine_rrdhost_find_or_create("dbengine-dataset");
@@ -2368,12 +2372,12 @@ void generate_dbengine_dataset(unsigned history_seconds)
thread_info[i]->time_max = 0;
thread_info[i]->done = 0;
completion_init(&thread_info[i]->charts_initialized);
- assert(0 == uv_thread_create(&thread_info[i]->thread, generate_dbengine_chart, thread_info[i]));
+ fatal_assert(0 == uv_thread_create(&thread_info[i]->thread, generate_dbengine_chart, thread_info[i]));
completion_wait_for(&thread_info[i]->charts_initialized);
completion_destroy(&thread_info[i]->charts_initialized);
}
for (i = 0 ; i < DSET_CHARTS ; ++i) {
- assert(0 == uv_thread_join(&thread_info[i]->thread));
+ fatal_assert(0 == uv_thread_join(&thread_info[i]->thread));
}
for (i = 0 ; i < DSET_CHARTS ; ++i) {
@@ -2518,7 +2522,7 @@ void dbengine_stress_test(unsigned TEST_DURATION_SEC, unsigned DSET_CHARTS, unsi
unsigned i, j;
time_t time_start, test_duration;
- error_log_limit_unlimited();
+ nd_log_limits_unlimited();
if (!TEST_DURATION_SEC)
TEST_DURATION_SEC = 10;
@@ -2575,7 +2579,7 @@ void dbengine_stress_test(unsigned TEST_DURATION_SEC, unsigned DSET_CHARTS, unsi
chart_threads[i]->done = 0;
chart_threads[i]->errors = chart_threads[i]->stored_metrics_nr = 0;
completion_init(&chart_threads[i]->charts_initialized);
- assert(0 == uv_thread_create(&chart_threads[i]->thread, generate_dbengine_chart, chart_threads[i]));
+ fatal_assert(0 == uv_thread_create(&chart_threads[i]->thread, generate_dbengine_chart, chart_threads[i]));
}
/* barrier so that subsequent queries can access valid chart data */
for (i = 0 ; i < DSET_CHARTS ; ++i) {
@@ -2597,7 +2601,7 @@ void dbengine_stress_test(unsigned TEST_DURATION_SEC, unsigned DSET_CHARTS, unsi
query_threads[i]->chart_threads[j] = chart_threads[j];
}
query_threads[i]->delete_old_data = DISK_SPACE_MB ? 1 : 0;
- assert(0 == uv_thread_create(&query_threads[i]->thread, query_dbengine_chart, query_threads[i]));
+ fatal_assert(0 == uv_thread_create(&query_threads[i]->thread, query_dbengine_chart, query_threads[i]));
}
sleep(TEST_DURATION_SEC);
/* stop workload */
@@ -2646,6 +2650,7 @@ void dbengine_stress_test(unsigned TEST_DURATION_SEC, unsigned DSET_CHARTS, unsi
rrdeng_prepare_exit((struct rrdengine_instance *)host->db[0].instance);
rrdhost_delete_charts(host);
rrdeng_exit((struct rrdengine_instance *)host->db[0].instance);
+ rrdeng_enq_cmd(NULL, RRDENG_OPCODE_SHUTDOWN_EVLOOP, NULL, NULL, STORAGE_PRIORITY_BEST_EFFORT, NULL, NULL);
rrd_unlock();
}