From 2b1b70665b2c0c2356e34ebc2e0a523d9acd118e Mon Sep 17 00:00:00 2001 From: "jabber.developer2" Date: Thu, 12 Mar 2026 21:02:22 +0300 Subject: [PATCH] fix(functests): fix send_receipt_request 60s timeout, rebalance groups, add per-test timing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix send_receipt_request test that wasted 60s on every run: - Change caps hash from sha-256 to sha-1 (profanity only supports sha-1 for standard caps path, sha-256 goes to unsupported-hash fallback) - Fix expected output: 'Buddy1 is online' → 'Buddy1 (laptop) is online' (resource is always shown for full JID presence) - Wrap prof_output_exact in assert_true so mismatches fail fast instead of silently waiting the full expect_timeout Rebalance test groups for parallel execution: - Move Disco tests (14) from Group 3 → Group 1 - Move DB History tests (12) from Group 2 → Group 3 - Before: G1=31s G2=63s G3=30s G4=37s (bottleneck 63s) - After: G1=46s G2=38s G3=40s G4=36s (bottleneck 46s, -27%) Add per-test wall-clock timing via clock_gettime(CLOCK_MONOTONIC) in init_prof_test/close_prof_test for profiling individual tests. --- tests/functionaltests/functionaltests.c | 78 ++++++++++++------------- tests/functionaltests/proftest.c | 12 ++++ tests/functionaltests/test_receipts.c | 4 +- 3 files changed, 53 insertions(+), 41 deletions(-) diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c index db1a7ff3..516c0a68 100644 --- a/tests/functionaltests/functionaltests.c +++ b/tests/functionaltests/functionaltests.c @@ -15,9 +15,9 @@ * 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 - * Group 2: Message, Receipts, Roster, DB History (+export/import with SQLite) - * Group 3: Presence, Disconnect, Disco + * 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 * * Parallel execution: @@ -83,7 +83,7 @@ main(int argc, char* argv[]) fprintf(stderr, "[PROF_TEST] Starting functional tests, group=%d\n", group); /* ============================================================ - * GROUP 1: Connect, Ping, Rooms, Software, Last Activity + * GROUP 1: Connect, Ping, Rooms, Software, Last Activity, Disco * Basic XMPP session establishment and server queries * ============================================================ */ const struct CMUnitTest group1_tests[] = { @@ -125,10 +125,26 @@ main(int argc, char* argv[]) /* Autoping slow tests - require sleep for timer triggers (~2s each) */ PROF_FUNC_TEST(autoping_sends_ping_after_interval), PROF_FUNC_TEST(autoping_server_not_supporting_ping), + + /* Service Discovery - XEP-0030 */ + PROF_FUNC_TEST(disco_info_shows_identity), + PROF_FUNC_TEST(disco_info_shows_features), + PROF_FUNC_TEST(disco_info_to_server), + PROF_FUNC_TEST(disco_info_to_jid), + PROF_FUNC_TEST(disco_info_not_found), + PROF_FUNC_TEST(disco_items_shows_items), + PROF_FUNC_TEST(disco_items_empty_result), + PROF_FUNC_TEST(disco_requires_connection), + PROF_FUNC_TEST(disco_items_to_jid), + PROF_FUNC_TEST(disco_info_empty_result), + PROF_FUNC_TEST(disco_info_multiple_identities), + PROF_FUNC_TEST(disco_info_without_name), + PROF_FUNC_TEST(disco_items_without_name), + PROF_FUNC_TEST(disco_info_service_unavailable), }; /* ============================================================ - * GROUP 2: Message, Receipts, Roster, DB History + * GROUP 2: Message, Receipts, Roster, Export/Import * Core messaging and contact management * ============================================================ */ const struct CMUnitTest group2_tests[] = { @@ -162,25 +178,11 @@ main(int argc, char* argv[]) PROF_FUNC_TEST(sends_remove_item), PROF_FUNC_TEST(sends_remove_item_nick), PROF_FUNC_TEST(sends_nick_change), - - /* Database persistence - message write+read round-trip */ - PROF_FUNC_TEST(message_db_history_on_reopen), - PROF_FUNC_TEST(message_db_history_multiple), - PROF_FUNC_TEST(message_db_history_contact_isolation), - PROF_FUNC_TEST(message_db_history_special_chars), - PROF_FUNC_TEST(message_db_history_outgoing), - PROF_FUNC_TEST(message_db_history_dialog), - PROF_FUNC_TEST(message_db_history_empty), - PROF_FUNC_TEST(message_db_history_long_message), - PROF_FUNC_TEST(message_db_history_newline), - PROF_FUNC_TEST(message_db_history_service_chars), - PROF_FUNC_TEST(message_db_history_verify), - PROF_FUNC_TEST(message_db_history_lmc), }; /* ============================================================ - * GROUP 3: Presence, Disconnect, Disco - * Status management, clean teardown, service discovery + * GROUP 3: Presence, Disconnect, DB History + * Status management, clean teardown, message persistence * ============================================================ */ const struct CMUnitTest group3_tests[] = { /* Presence - online/away/xa/dnd/chat status management */ @@ -203,21 +205,19 @@ main(int argc, char* argv[]) /* Disconnect - clean session termination */ PROF_FUNC_TEST(disconnect_ends_session), - /* Service Discovery - XEP-0030 */ - PROF_FUNC_TEST(disco_info_shows_identity), - PROF_FUNC_TEST(disco_info_shows_features), - PROF_FUNC_TEST(disco_info_to_server), - PROF_FUNC_TEST(disco_info_to_jid), - PROF_FUNC_TEST(disco_info_not_found), - PROF_FUNC_TEST(disco_items_shows_items), - PROF_FUNC_TEST(disco_items_empty_result), - PROF_FUNC_TEST(disco_requires_connection), - PROF_FUNC_TEST(disco_items_to_jid), - PROF_FUNC_TEST(disco_info_empty_result), - PROF_FUNC_TEST(disco_info_multiple_identities), - PROF_FUNC_TEST(disco_info_without_name), - PROF_FUNC_TEST(disco_items_without_name), - PROF_FUNC_TEST(disco_info_service_unavailable), + /* Database persistence - message write+read round-trip */ + PROF_FUNC_TEST(message_db_history_on_reopen), + PROF_FUNC_TEST(message_db_history_multiple), + PROF_FUNC_TEST(message_db_history_contact_isolation), + PROF_FUNC_TEST(message_db_history_special_chars), + PROF_FUNC_TEST(message_db_history_outgoing), + PROF_FUNC_TEST(message_db_history_dialog), + PROF_FUNC_TEST(message_db_history_empty), + PROF_FUNC_TEST(message_db_history_long_message), + PROF_FUNC_TEST(message_db_history_newline), + PROF_FUNC_TEST(message_db_history_service_chars), + PROF_FUNC_TEST(message_db_history_verify), + PROF_FUNC_TEST(message_db_history_lmc), }; /* ============================================================ @@ -274,9 +274,9 @@ main(int argc, char* argv[]) const struct CMUnitTest* tests; size_t count; } groups[] = { - { "Group 1: Connect/Ping/Rooms/Software/LastActivity/Autoping", group1_tests, ARRAY_SIZE(group1_tests) }, - { "Group 2: Message/Receipts/Roster/DBHistory", group2_tests, ARRAY_SIZE(group2_tests) }, - { "Group 3: Presence/Disconnect/Disco", group3_tests, ARRAY_SIZE(group3_tests) }, + { "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) }, }; const int num_groups = ARRAY_SIZE(groups); diff --git a/tests/functionaltests/proftest.c b/tests/functionaltests/proftest.c index 525a7d01..7e21dc69 100644 --- a/tests/functionaltests/proftest.c +++ b/tests/functionaltests/proftest.c @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -77,6 +78,9 @@ static size_t output_len = 0; /* Timeout for expect operations in seconds */ static int expect_timeout = EXPECT_TIMEOUT_DEFAULT; +/* Per-test wall-clock timer */ +static struct timespec test_start_ts; + gboolean _create_dir(const char *name) { @@ -275,6 +279,7 @@ prof_start(void) int init_prof_test(void **state) { + clock_gettime(CLOCK_MONOTONIC, &test_start_ts); /* 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; @@ -427,6 +432,13 @@ close_prof_test(void **state) } stbbr_stop(); + + struct timespec now; + 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); + return 0; } diff --git a/tests/functionaltests/test_receipts.c b/tests/functionaltests/test_receipts.c index 9a173a7f..ffbe1955 100644 --- a/tests/functionaltests/test_receipts.c +++ b/tests/functionaltests/test_receipts.c @@ -44,11 +44,11 @@ send_receipt_request(void **state) "" "15" "My status" - "" + "" "" ); - prof_output_exact("Buddy1 is online, \"My status\""); + assert_true(prof_output_exact("Buddy1 (laptop) is online, \"My status\"")); prof_input("/msg Buddy1"); prof_input("/resource set laptop");