mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-24 13:56:22 +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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user