mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-27 05:56:21 +00:00
test: add database stress tests (14 tests, rapid writes, large messages, LMC chains, dedup)
This commit is contained in:
@@ -175,6 +175,7 @@ unittest_sources = \
|
|||||||
tests/unittests/test_plugins_disco.c tests/unittests/test_plugins_disco.h \
|
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_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_export.c tests/unittests/test_database_export.h \
|
||||||
|
tests/unittests/test_database_stress.c tests/unittests/test_database_stress.h \
|
||||||
tests/unittests/unittests.c
|
tests/unittests/unittests.c
|
||||||
|
|
||||||
functionaltest_sources = \
|
functionaltest_sources = \
|
||||||
|
|||||||
@@ -354,8 +354,7 @@ init_prof_test(void **state)
|
|||||||
|
|
||||||
/* Pre-write profrc with UI/notification defaults to ensure consistent,
|
/* Pre-write profrc with UI/notification defaults to ensure consistent,
|
||||||
* deterministic output across tests (no timestamps, no roster/occupants
|
* deterministic output across tests (no timestamps, no roster/occupants
|
||||||
* panels, low input-blocking delay for fast command processing).
|
* panels, low input-blocking delay for fast command processing). */
|
||||||
* If PROF_FLATFILE=1, also select the flat-file database backend. */
|
|
||||||
char profrc_path[512];
|
char profrc_path[512];
|
||||||
snprintf(profrc_path, sizeof(profrc_path),
|
snprintf(profrc_path, sizeof(profrc_path),
|
||||||
"%s/profanity/profrc", xdg_config_home);
|
"%s/profanity/profrc", xdg_config_home);
|
||||||
@@ -431,40 +430,6 @@ close_prof_test(void **state)
|
|||||||
return 0;
|
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
|
void
|
||||||
prof_input(const char *input)
|
prof_input(const char *input)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ int init_prof_test(void** state);
|
|||||||
int close_prof_test(void** state);
|
int close_prof_test(void** state);
|
||||||
|
|
||||||
void prof_start(void);
|
void prof_start(void);
|
||||||
void prof_stop(void);
|
|
||||||
void prof_connect(void);
|
void prof_connect(void);
|
||||||
void prof_connect_with_roster(const char* roster);
|
void prof_connect_with_roster(const char* roster);
|
||||||
void prof_input(const char* input);
|
void prof_input(const char* input);
|
||||||
|
|||||||
1131
tests/unittests/test_database_stress.c
Normal file
1131
tests/unittests/test_database_stress.c
Normal file
File diff suppressed because it is too large
Load Diff
28
tests/unittests/test_database_stress.h
Normal file
28
tests/unittests/test_database_stress.h
Normal 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);
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
#include "test_callbacks.h"
|
#include "test_callbacks.h"
|
||||||
#include "test_plugins_disco.h"
|
#include "test_plugins_disco.h"
|
||||||
#include "test_database_export.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)
|
#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_parsed_line_free_null_safe),
|
||||||
cmocka_unit_test(test_ff_parse_line_no_space_rejected),
|
cmocka_unit_test(test_ff_parse_line_no_space_rejected),
|
||||||
cmocka_unit_test(test_ff_parse_line_unclosed_bracket),
|
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);
|
return cmocka_run_group_tests(all_tests, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user