mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-18 23:36:21 +00:00
test(functests): migration/MUC/timestamp tests, group rebalancing
Add 11 new export/import tests (24 → 35): 4 MUC database, 3 timestamp verification, 3 migration stress, 1 LMC correction with negative assert. Add delay-stamp timestamp checks to 5 base tests via /time chat set iso8601 and /history on (previously passed by accident from PTY buffer). Replace magic numbers: NEGATIVE_ASSERT_TIMEOUT, MIN_ELAPSED_INIT. Add per-test slow/fast thresholds and TZ override (prof_test_tz). Rebalance groups by whole logical blocks (spread 46s → 3s): G1=52s G2=50s G3=53s G4=53s. All 129 tests pass.
This commit is contained in:
@@ -14,11 +14,11 @@
|
||||
* flaky tests caused by leftover state. The overhead is acceptable since
|
||||
* functional tests run less frequently than unit tests.
|
||||
*
|
||||
* Tests are organized into groups for better maintainability and parallel execution:
|
||||
* Group 1: Connect, Ping, Rooms, Software, Last Activity, Autoping, Disco
|
||||
* Group 2: Message, Receipts, Roster, Export/Import (+SQLite)
|
||||
* Group 3: Presence, Disconnect, DB History
|
||||
* Group 4: Chat Session, MUC, Carbons
|
||||
* Tests are organized into groups balanced for parallel execution:
|
||||
* Group 1: Connect, Ping, Rooms, Software, Last Activity, Autoping, Disco, Roster
|
||||
* Group 2: Export/Import (core + bidirectional), Receipts
|
||||
* Group 3: Presence, Disconnect, DB History, Message, MUC Database
|
||||
* Group 4: Chat Session, MUC, Carbons, Migration Stress
|
||||
*
|
||||
* Parallel execution:
|
||||
* ./functionaltests - run all tests sequentially
|
||||
@@ -61,7 +61,19 @@
|
||||
#endif
|
||||
|
||||
/* Macro to wrap each test with setup/teardown functions */
|
||||
#define PROF_FUNC_TEST(test) cmocka_unit_test_setup_teardown(test, init_prof_test, close_prof_test)
|
||||
#define PROF_FUNC_TEST(test) { #test, test, init_prof_test, close_prof_test, #test }
|
||||
|
||||
#ifdef HAVE_SQLITE
|
||||
/* Custom init that sets a non-UTC timezone (POSIX TST-3 = UTC+3) */
|
||||
static int
|
||||
init_tz_plus3_test(void** state)
|
||||
{
|
||||
prof_test_tz = "TST-3";
|
||||
int ret = init_prof_test(state);
|
||||
prof_test_tz = "UTC";
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
@@ -83,8 +95,8 @@ main(int argc, char* argv[])
|
||||
fprintf(stderr, "[PROF_TEST] Starting functional tests, group=%d\n", group);
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 1: Connect, Ping, Rooms, Software, Last Activity, Disco
|
||||
* Basic XMPP session establishment and server queries
|
||||
* GROUP 1: Connect, Ping, Rooms, Software, Last Activity, Disco, Roster
|
||||
* Basic XMPP session establishment, server queries, contact mgmt
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group1_tests[] = {
|
||||
/* Connection tests - verify login, roster, bookmarks */
|
||||
@@ -141,11 +153,18 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(disco_info_without_name),
|
||||
PROF_FUNC_TEST(disco_items_without_name),
|
||||
PROF_FUNC_TEST(disco_info_service_unavailable),
|
||||
|
||||
/* Roster management - add/remove/rename contacts */
|
||||
PROF_FUNC_TEST(sends_new_item),
|
||||
PROF_FUNC_TEST(sends_new_item_nick),
|
||||
PROF_FUNC_TEST(sends_remove_item),
|
||||
PROF_FUNC_TEST(sends_remove_item_nick),
|
||||
PROF_FUNC_TEST(sends_nick_change),
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 2: Message, Receipts, Roster, Export/Import
|
||||
* Core messaging and contact management
|
||||
* GROUP 2: Export/Import (core + bidirectional), Receipts
|
||||
* Cross-backend migration, message timestamp round-trip
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group2_tests[] = {
|
||||
#ifdef HAVE_SQLITE
|
||||
@@ -160,29 +179,26 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(verify_after_export),
|
||||
PROF_FUNC_TEST(switch_backends_independent_messages),
|
||||
PROF_FUNC_TEST(export_empty_contact),
|
||||
#endif
|
||||
|
||||
/* Basic message send/receive */
|
||||
PROF_FUNC_TEST(message_send),
|
||||
PROF_FUNC_TEST(message_receive_console),
|
||||
PROF_FUNC_TEST(message_receive_chatwin),
|
||||
/* Bidirectional migration — split timelines merged across backends */
|
||||
PROF_FUNC_TEST(bidirectional_merge_to_flatfile),
|
||||
PROF_FUNC_TEST(bidirectional_merge_to_sqlite),
|
||||
PROF_FUNC_TEST(migration_incremental_accumulation),
|
||||
PROF_FUNC_TEST(roundtrip_full_cycle),
|
||||
PROF_FUNC_TEST(export_timestamps_preserved),
|
||||
PROF_FUNC_TEST(import_timestamps_preserved),
|
||||
{ "export_timestamps_non_utc", export_timestamps_non_utc, init_tz_plus3_test, close_prof_test, "export_timestamps_non_utc" },
|
||||
#endif
|
||||
|
||||
/* Message receipts - XEP-0184 */
|
||||
PROF_FUNC_TEST(does_not_send_receipt_request_to_barejid),
|
||||
PROF_FUNC_TEST(send_receipt_request),
|
||||
PROF_FUNC_TEST(send_receipt_on_request),
|
||||
|
||||
/* Roster management - add/remove/rename contacts */
|
||||
PROF_FUNC_TEST(sends_new_item),
|
||||
PROF_FUNC_TEST(sends_new_item_nick),
|
||||
PROF_FUNC_TEST(sends_remove_item),
|
||||
PROF_FUNC_TEST(sends_remove_item_nick),
|
||||
PROF_FUNC_TEST(sends_nick_change),
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 3: Presence, Disconnect, DB History
|
||||
* Status management, clean teardown, message persistence
|
||||
* GROUP 3: Presence, Disconnect, DB History, Message, MUC Database
|
||||
* Status management, message persistence, MUC storage
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group3_tests[] = {
|
||||
/* Presence - online/away/xa/dnd/chat status management */
|
||||
@@ -218,11 +234,24 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(message_db_history_service_chars),
|
||||
PROF_FUNC_TEST(message_db_history_verify),
|
||||
PROF_FUNC_TEST(message_db_history_lmc),
|
||||
|
||||
/* Basic message send/receive */
|
||||
PROF_FUNC_TEST(message_send),
|
||||
PROF_FUNC_TEST(message_receive_console),
|
||||
PROF_FUNC_TEST(message_receive_chatwin),
|
||||
|
||||
#ifdef HAVE_SQLITE
|
||||
/* MUC (groupchat) database — export/import of type="muc" messages */
|
||||
PROF_FUNC_TEST(muc_export_sqlite_to_flatfile),
|
||||
PROF_FUNC_TEST(muc_import_flatfile_to_sqlite),
|
||||
PROF_FUNC_TEST(muc_export_timestamps_preserved),
|
||||
PROF_FUNC_TEST(muc_export_multiple_rooms),
|
||||
#endif
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 4: Chat Session, MUC, Carbons
|
||||
* Session routing, multi-user chat, message synchronization
|
||||
* GROUP 4: Chat Session, MUC, Carbons, Migration Stress
|
||||
* Session routing, multi-user chat, message sync, stress tests
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group4_tests[] = {
|
||||
/* Chat session management - bare/full JID routing */
|
||||
@@ -265,6 +294,13 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(receive_carbon),
|
||||
PROF_FUNC_TEST(receive_self_carbon),
|
||||
PROF_FUNC_TEST(receive_private_carbon),
|
||||
|
||||
#ifdef HAVE_SQLITE
|
||||
/* Migration stress — pool accumulation, LMC chains, large bodies */
|
||||
PROF_FUNC_TEST(export_message_pool_dated),
|
||||
PROF_FUNC_TEST(export_lmc_pool_multiple),
|
||||
PROF_FUNC_TEST(export_large_body_survives),
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Test group registry for easy extension */
|
||||
@@ -274,10 +310,10 @@ main(int argc, char* argv[])
|
||||
const struct CMUnitTest* tests;
|
||||
size_t count;
|
||||
} groups[] = {
|
||||
{ "Group 1: Connect/Ping/Rooms/Software/LastActivity/Autoping/Disco", group1_tests, ARRAY_SIZE(group1_tests) },
|
||||
{ "Group 2: Message/Receipts/Roster/ExportImport", group2_tests, ARRAY_SIZE(group2_tests) },
|
||||
{ "Group 3: Presence/Disconnect/DBHistory", group3_tests, ARRAY_SIZE(group3_tests) },
|
||||
{ "Group 4: Session/MUC/Carbons", group4_tests, ARRAY_SIZE(group4_tests) },
|
||||
{ "Group 1: Connect/Ping/Disco/Roster", group1_tests, ARRAY_SIZE(group1_tests) },
|
||||
{ "Group 2: ExportImport/Receipts", group2_tests, ARRAY_SIZE(group2_tests) },
|
||||
{ "Group 3: Presence/Disconnect/DBHistory/Message/MUC-DB", group3_tests, ARRAY_SIZE(group3_tests) },
|
||||
{ "Group 4: Session/MUC/Carbons/MigrationStress", group4_tests, ARRAY_SIZE(group4_tests) },
|
||||
};
|
||||
const int num_groups = ARRAY_SIZE(groups);
|
||||
|
||||
|
||||
@@ -44,6 +44,13 @@
|
||||
#define EXPECT_TIMEOUT_DEFAULT 30
|
||||
#define EXPECT_TIMEOUT_CONNECT 60
|
||||
|
||||
/* Test duration thresholds (seconds) */
|
||||
#define SLOW_TEST_THRESHOLD_S 20
|
||||
#define FAST_TEST_THRESHOLD_S 0.3
|
||||
|
||||
/* Sentinel "infinity" for min-elapsed tracking (any real test is faster) */
|
||||
#define MIN_ELAPSED_INIT 1e9
|
||||
|
||||
/* Terminal dimensions for forkpty */
|
||||
#define PTY_ROWS 24
|
||||
#define PTY_COLS 300
|
||||
@@ -80,6 +87,16 @@ static int expect_timeout = EXPECT_TIMEOUT_DEFAULT;
|
||||
|
||||
/* Per-test wall-clock timer */
|
||||
static struct timespec test_start_ts;
|
||||
static const char *current_test_name;
|
||||
static double min_elapsed = MIN_ELAPSED_INIT;
|
||||
static const char *min_test_name = "(none)";
|
||||
|
||||
/* Per-test threshold overrides (0 = use default) */
|
||||
double prof_test_slow_threshold = 0;
|
||||
double prof_test_fast_threshold = 0;
|
||||
|
||||
/* Timezone for profanity child process (see proftest.h) */
|
||||
const char *prof_test_tz = "UTC";
|
||||
|
||||
gboolean
|
||||
_create_dir(const char *name)
|
||||
@@ -247,7 +264,13 @@ prof_start(void)
|
||||
/* Reset output buffer */
|
||||
output_len = 0;
|
||||
output_buffer[0] = '\0';
|
||||
|
||||
|
||||
/* Force UTC so delay-stamp timestamps render deterministically
|
||||
* regardless of the host timezone (needed for functional tests
|
||||
* that verify rendered timestamp strings). */
|
||||
setenv("TZ", prof_test_tz, 1);
|
||||
tzset();
|
||||
|
||||
child_pid = forkpty(&fd, NULL, NULL, &ws);
|
||||
|
||||
if (child_pid < 0) {
|
||||
@@ -280,6 +303,9 @@ int
|
||||
init_prof_test(void **state)
|
||||
{
|
||||
clock_gettime(CLOCK_MONOTONIC, &test_start_ts);
|
||||
current_test_name = state && *state ? (const char *)*state : "unknown";
|
||||
prof_test_slow_threshold = 0;
|
||||
prof_test_fast_threshold = 0;
|
||||
/* Get test group from environment for static resource allocation */
|
||||
const char *group_env = getenv("PROF_TEST_GROUP");
|
||||
int group = group_env ? atoi(group_env) : 0;
|
||||
@@ -437,7 +463,21 @@ close_prof_test(void **state)
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
double elapsed = (now.tv_sec - test_start_ts.tv_sec)
|
||||
+ (now.tv_nsec - test_start_ts.tv_nsec) / 1e9;
|
||||
printf("[PROF_TEST] test took %.3f s\n", elapsed);
|
||||
if (elapsed < min_elapsed) {
|
||||
min_elapsed = elapsed;
|
||||
min_test_name = current_test_name;
|
||||
}
|
||||
printf("[PROF_TEST] test '%s' took %.3f s (min: %.3fs '%s')\n",
|
||||
current_test_name, elapsed, min_elapsed, min_test_name);
|
||||
double slow_thr = prof_test_slow_threshold > 0 ? prof_test_slow_threshold : SLOW_TEST_THRESHOLD_S;
|
||||
double fast_thr = prof_test_fast_threshold > 0 ? prof_test_fast_threshold : FAST_TEST_THRESHOLD_S;
|
||||
if (elapsed >= slow_thr) {
|
||||
print_message("[PROF_TEST] WARNING: slow test '%s' \u2014 %.1fs (threshold %.1fs)\n",
|
||||
current_test_name, elapsed, slow_thr);
|
||||
} else if (elapsed < fast_thr) {
|
||||
print_message("[PROF_TEST] WARNING: suspiciously fast test '%s' \u2014 %.3fs (min %.3fs)\n",
|
||||
current_test_name, elapsed, fast_thr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -25,4 +25,14 @@ int prof_output_regex(const char* text);
|
||||
void prof_timeout(int timeout);
|
||||
void prof_timeout_reset(void);
|
||||
|
||||
/* Short timeout for negative assertions (seconds) */
|
||||
#define NEGATIVE_ASSERT_TIMEOUT 3
|
||||
|
||||
/* Per-test threshold overrides (0 = use default) */
|
||||
extern double prof_test_slow_threshold;
|
||||
extern double prof_test_fast_threshold;
|
||||
|
||||
/* Timezone used for profanity child process (default "UTC") */
|
||||
extern const char *prof_test_tz;
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,3 +8,17 @@ void import_double_dedup(void** state);
|
||||
void verify_after_export(void** state);
|
||||
void switch_backends_independent_messages(void** state);
|
||||
void export_empty_contact(void** state);
|
||||
void export_message_pool_dated(void** state);
|
||||
void export_lmc_pool_multiple(void** state);
|
||||
void export_large_body_survives(void** state);
|
||||
void bidirectional_merge_to_flatfile(void** state);
|
||||
void bidirectional_merge_to_sqlite(void** state);
|
||||
void migration_incremental_accumulation(void** state);
|
||||
void roundtrip_full_cycle(void** state);
|
||||
void export_timestamps_preserved(void** state);
|
||||
void import_timestamps_preserved(void** state);
|
||||
void export_timestamps_non_utc(void** state);
|
||||
void muc_export_sqlite_to_flatfile(void** state);
|
||||
void muc_import_flatfile_to_sqlite(void** state);
|
||||
void muc_export_timestamps_preserved(void** state);
|
||||
void muc_export_multiple_rooms(void** state);
|
||||
|
||||
Reference in New Issue
Block a user