test: add database stress tests (14 tests, rapid writes, large messages, LMC chains, dedup)
All checks were successful
CI Code / Check spelling (pull_request) Successful in 17s
CI Code / Check coding style (pull_request) Successful in 31s
CI Code / Code Coverage (pull_request) Successful in 4m1s
CI Code / Linux (debian) (pull_request) Successful in 5m38s
CI Code / Linux (ubuntu) (pull_request) Successful in 5m39s
CI Code / Linux (arch) (pull_request) Successful in 6m7s

This commit is contained in:
2026-03-12 11:13:45 +03:00
parent 71f9ab5007
commit 0d38a0a2cb
6 changed files with 1178 additions and 37 deletions

View File

@@ -175,6 +175,7 @@ unittest_sources = \
tests/unittests/test_plugins_disco.c tests/unittests/test_plugins_disco.h \
tests/unittests/test_forced_encryption.c tests/unittests/test_forced_encryption.h \
tests/unittests/test_database_export.c tests/unittests/test_database_export.h \
tests/unittests/test_database_stress.c tests/unittests/test_database_stress.h \
tests/unittests/unittests.c
functionaltest_sources = \

View File

@@ -354,8 +354,7 @@ init_prof_test(void **state)
/* Pre-write profrc with UI/notification defaults to ensure consistent,
* deterministic output across tests (no timestamps, no roster/occupants
* panels, low input-blocking delay for fast command processing).
* If PROF_FLATFILE=1, also select the flat-file database backend. */
* panels, low input-blocking delay for fast command processing). */
char profrc_path[512];
snprintf(profrc_path, sizeof(profrc_path),
"%s/profanity/profrc", xdg_config_home);
@@ -431,40 +430,6 @@ close_prof_test(void **state)
return 0;
}
void
prof_stop(void)
{
if (fd > 0 && child_pid > 0) {
prof_input("/quit");
sleep_ms(QUIT_GRACE_MS);
close(fd);
fd = 0;
int exited = 0;
for (int i = 0; i < SHUTDOWN_POLL_MAX; i++) {
if (waitpid(child_pid, NULL, WNOHANG) != 0) {
exited = 1;
break;
}
sleep_ms(SHUTDOWN_POLL_MS);
}
if (!exited) {
kill(child_pid, SIGTERM);
for (int i = 0; i < SIGTERM_POLL_MAX; i++) {
if (waitpid(child_pid, NULL, WNOHANG) != 0) { exited = 1; break; }
sleep_ms(SHUTDOWN_POLL_MS);
}
if (!exited) {
kill(child_pid, SIGKILL);
waitpid(child_pid, NULL, 0);
}
}
child_pid = 0;
}
/* Reset output buffer for clean restart */
output_len = 0;
output_buffer[0] = '\0';
}
void
prof_input(const char *input)
{

View File

@@ -15,7 +15,6 @@ int init_prof_test(void** state);
int close_prof_test(void** state);
void prof_start(void);
void prof_stop(void);
void prof_connect(void);
void prof_connect_with_roster(const char* roster);
void prof_input(const char* input);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,28 @@
/* test_database_stress.h — stress tests for database I/O, MUC, large messages,
* export/import roundtrip under load, and index/cache correctness. */
/* High-throughput write + parse */
void test_stress_rapid_write_parse_1000(void** state);
void test_stress_rapid_write_parse_10000(void** state);
/* MUC (chat room) messages */
void test_stress_muc_many_participants(void** state);
void test_stress_muc_rapid_messages(void** state);
/* Large messages */
void test_stress_large_message_1mb(void** state);
void test_stress_large_message_body_with_special_chars(void** state);
void test_stress_many_large_messages_100(void** state);
/* Index and ID cache correctness under load */
void test_stress_index_build_10000_lines(void** state);
void test_stress_index_extend_append(void** state);
void test_stress_id_cache_dedup_correctness(void** state);
/* Export / import roundtrip under load */
void test_stress_export_merge_dedup_1000(void** state);
void test_stress_mixed_types_and_encodings(void** state);
/* LMC correction chains under load */
void test_stress_lmc_chain_deep(void** state);
void test_stress_lmc_many_corrections(void** state);

View File

@@ -37,6 +37,7 @@
#include "test_callbacks.h"
#include "test_plugins_disco.h"
#include "test_database_export.h"
#include "test_database_stress.h"
#define muc_unit_test(f) cmocka_unit_test_setup_teardown(f, muc_before_test, muc_after_test)
@@ -709,6 +710,22 @@ main(int argc, char* argv[])
cmocka_unit_test(test_ff_parsed_line_free_null_safe),
cmocka_unit_test(test_ff_parse_line_no_space_rejected),
cmocka_unit_test(test_ff_parse_line_unclosed_bracket),
// Stress tests
cmocka_unit_test(test_stress_rapid_write_parse_1000),
cmocka_unit_test(test_stress_rapid_write_parse_10000),
cmocka_unit_test(test_stress_muc_many_participants),
cmocka_unit_test(test_stress_muc_rapid_messages),
cmocka_unit_test(test_stress_large_message_1mb),
cmocka_unit_test(test_stress_large_message_body_with_special_chars),
cmocka_unit_test(test_stress_many_large_messages_100),
cmocka_unit_test(test_stress_index_build_10000_lines),
cmocka_unit_test(test_stress_index_extend_append),
cmocka_unit_test(test_stress_id_cache_dedup_correctness),
cmocka_unit_test(test_stress_export_merge_dedup_1000),
cmocka_unit_test(test_stress_mixed_types_and_encodings),
cmocka_unit_test(test_stress_lmc_chain_deep),
cmocka_unit_test(test_stress_lmc_many_corrections),
};
return cmocka_run_group_tests(all_tests, NULL, NULL);
}