Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wazp6-002Dmi-38 for pgsql-hackers@arkaria.postgresql.org; Sat, 20 Jun 2026 17:49:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wazp5-001zrD-2x for pgsql-hackers@arkaria.postgresql.org; Sat, 20 Jun 2026 17:49:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wazp5-001zr5-1b for pgsql-hackers@lists.postgresql.org; Sat, 20 Jun 2026 17:49:39 +0000 Received: from mail-yw1-x1132.google.com ([2607:f8b0:4864:20::1132]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wazp4-00000001KE4-09V0 for pgsql-hackers@postgresql.org; Sat, 20 Jun 2026 17:49:38 +0000 Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-7e2fd65f968so31598247b3.3 for ; Sat, 20 Jun 2026 10:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781977777; x=1782582577; darn=postgresql.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0CobqtW1zN8/tZIoSu6ixMvoS4amebc9x58opXtKzck=; b=End0/0CWpiP9nB5GlNJ5stfQEwiOfsxXiWCyBe0mEm9NDCd8dA2ViVW45CFJ5oQKSn pE0BOTvAFQHLJjuusRhURXNjzYw+lnzHp1g94FsqkTcXyGZQee+20vW8GGf22xv38hA3 y7l7SQ5M4IdcsgTPtNxaaVl+wWH8TynZPmpd0rl5xYP6JMiOL/MEV2Ca+CCby0vlVfKD YWNIDkXhhk+e80Q2W6i0kdjvVmzImjEbGFUApnVFHXzUqXx6lq+cm1IE7y0cPlm7izG3 eFahyT4Hh90Ko2TFf+w9pP+v2TDr4ajJg2oIagsnxk6+WwwkpyI5rdb6tdKWOREYe4/Y a9Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781977777; x=1782582577; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0CobqtW1zN8/tZIoSu6ixMvoS4amebc9x58opXtKzck=; b=h2b+saCbYjQ6fbwm6aG6zhS4uCAZ7tLy7Ql91arDLrrmMmfU0BMJrVuEcsmBZ7CtrX 2Ai3xzzw0XS0oqtKKlQUe6gFfq6Vfaj9PWg8tjwdvL/PMNyqWdV1KRBJMmTq0BMJjCGw PBo8z81o0N9E7WqtWlJb2uGQDDcMrVdqdx8QxphKvmbCfL28ev3NHYvuZvK/vjgrOi2m pmh1deTrChZNArfHwwL/m4cupM2CAYWN2Ce022A3huJ1iIjyRb0dPuEhAnqBc9Cf/1vA Xu3vrRGls0/tbJFWTDXB+pEEH5LiLS3Z8Jeeei2874+nwJiyf4n+A9ucza/WpMKOf8cD NEow== X-Gm-Message-State: AOJu0YwUvhVhJRITGV6APiUxTJ/zrZaY7X0/nzMs5ks9Lg+pqJbCu2K5 vUIYF3QG4rKJ9QnexCwuJiv7/4HHV1U82a0Usv3cAO/bq8f4cqD1fq7l X-Gm-Gg: AfdE7cnwmRtczDj/tF9abwDcgUynNkSB46AslRqvkpmS/LRSPJ20zPXRsUHrp8oqxnd oawcyrqdzQMfulzDPu2xH2SShbu7kBiNAfXVBYubEBJqPVu0iU6njY/H1R39k15pvRIZrpcPK6K Ptqld5qGcUo0gmeChrz8jQFpF9UD72XHi2NBk7bnlD/7muh5QOxYS+fYbFF17g2NmiHgo/5tXEE oJlbkPxV2P1yd621yumlxdYO8p3L/b3HZQhPqbTSAUwm63tcC4wF7EmziSqBRTx6iIV8XsKxhyM Pnema0lBLWiigzCFyXWZa7vI/PY3DaiOSDtNC5Q5C27kuW6CyE0+QryFPUluCo8UlUXu71BhoZ1 6CekqzIiOkc/jIZ+RWMAAKYHdCGLZRoVvVMEbXF7a0Scjme5VJHM5ONd3Wn6H/krZT6sjoB9Z6W vs8q8OcoGQPkSQ+bvgg4ycs1G7g7V98wy3d5F4TLXEc6hG00/xGn46GFo86HTJ6aN6I1srXe5Bv RKV X-Received: by 2002:a05:690c:7103:b0:7db:d730:4b8c with SMTP id 00721157ae682-80266164053mr47508487b3.32.1781977776669; Sat, 20 Jun 2026 10:49:36 -0700 (PDT) Received: from alibaba.. ([98.97.79.248]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8025cf69b5asm12415077b3.20.2026.06.20.10.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jun 2026 10:49:36 -0700 (PDT) From: Zakariyah Ali To: Kyotaro Horiguchi Cc: pgsql-hackers@postgresql.org, Zakariyah Ali Subject: [PATCH v2] Standardize log polling using wait_for_log() across recovery tests Date: Sat, 20 Jun 2026 18:49:06 +0100 Message-ID: <20260620174907.122631-1-zakariyahali100@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260606203222.108048-1-zakariyahali100@gmail.com> References: <20260606203222.108048-1-zakariyahali100@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This patch replaces open-coded log wait loops with the existing wait_for_log() helper in the recovery test suite, specifically updating 019_replslot_limit.pl, 033_replay_tsp_drops.pl, and 041_checkpoint_at_promote.pl. This removes duplicated polling logic and ensures a consistent approach to waiting for specific log lines during tests. Signed-off-by: Zakariyah Ali --- src/test/recovery/t/019_replslot_limit.pl | 78 ++++--------------- src/test/recovery/t/033_replay_tsp_drops.pl | 16 ++-- .../recovery/t/041_checkpoint_at_promote.pl | 13 +--- 3 files changed, 23 insertions(+), 84 deletions(-) diff --git a/src/test/recovery/t/019_replslot_limit.pl b/src/test/recovery/t/019_replslot_limit.pl index a412faf51c6..3fdce739965 100644 --- a/src/test/recovery/t/019_replslot_limit.pl +++ b/src/test/recovery/t/019_replslot_limit.pl @@ -186,18 +186,9 @@ $node_primary->advance_wal(7); $node_primary->safe_psql('postgres', 'ALTER SYSTEM RESET max_wal_size; SELECT pg_reload_conf()'); $node_primary->safe_psql('postgres', "CHECKPOINT;"); -my $invalidated = 0; -for (my $i = 0; $i < 10 * $PostgreSQL::Test::Utils::timeout_default; $i++) -{ - if ($node_primary->log_contains( - 'invalidating obsolete replication slot "rep1"', $logstart)) - { - $invalidated = 1; - last; - } - usleep(100_000); -} -ok($invalidated, 'check that slot invalidation has been logged'); +ok( $node_primary->wait_for_log( + 'invalidating obsolete replication slot "rep1"', $logstart), + 'check that slot invalidation has been logged'); $result = $node_primary->safe_psql( 'postgres', @@ -208,17 +199,8 @@ is($result, "rep1|f|t|lost|", 'check that the slot became inactive and the state "lost" persists'); # Wait until current checkpoint ends -my $checkpoint_ended = 0; -for (my $i = 0; $i < 10 * $PostgreSQL::Test::Utils::timeout_default; $i++) -{ - if ($node_primary->log_contains("checkpoint complete: ", $logstart)) - { - $checkpoint_ended = 1; - last; - } - usleep(100_000); -} -ok($checkpoint_ended, 'waited for checkpoint to end'); +ok( $node_primary->wait_for_log("checkpoint complete: ", $logstart), + 'waited for checkpoint to end'); # The invalidated slot shouldn't keep the old-segment horizon back; # see bug #17103: https://postgr.es/m/17103-004130e8f27782c9@postgresql.org @@ -238,18 +220,10 @@ is($oldestseg, $redoseg, "check that segments have been removed"); $logstart = -s $node_standby->logfile; $node_standby->start; -my $failed = 0; -for (my $i = 0; $i < 10 * $PostgreSQL::Test::Utils::timeout_default; $i++) -{ - if ($node_standby->log_contains( - "This replication slot has been invalidated due to \"wal_removed\".", - $logstart)) - { - $failed = 1; - last; - } - usleep(100_000); -} +my $failed = + $node_standby->wait_for_log( + "This replication slot has been invalidated due to \"wal_removed\".", + $logstart); ok($failed, 'check that replication has been broken'); $node_primary->stop; @@ -374,20 +348,10 @@ $logstart = -s $node_primary3->logfile; kill 'STOP', $senderpid, $receiverpid; $node_primary3->advance_wal(2); -my $msg_logged = 0; -my $max_attempts = $PostgreSQL::Test::Utils::timeout_default; -while ($max_attempts-- >= 0) -{ - if ($node_primary3->log_contains( - "terminating process $senderpid to release replication slot \"rep3\"", - $logstart)) - { - $msg_logged = 1; - last; - } - sleep 1; -} -ok($msg_logged, "walsender termination logged"); +ok( $node_primary3->wait_for_log( + "terminating process $senderpid to release replication slot \"rep3\"", + $logstart), + "walsender termination logged"); # Now let the walsender continue; slot should be killed now. # (Must not let walreceiver run yet; otherwise the standby could start another @@ -398,19 +362,9 @@ $node_primary3->poll_query_until('postgres', "lost") or die "timed out waiting for slot to be lost"; -$msg_logged = 0; -$max_attempts = $PostgreSQL::Test::Utils::timeout_default; -while ($max_attempts-- >= 0) -{ - if ($node_primary3->log_contains( - 'invalidating obsolete replication slot "rep3"', $logstart)) - { - $msg_logged = 1; - last; - } - sleep 1; -} -ok($msg_logged, "slot invalidation logged"); +ok( $node_primary3->wait_for_log( + 'invalidating obsolete replication slot "rep3"', $logstart), + "slot invalidation logged"); # Now let the walreceiver continue, so that the node can be stopped cleanly kill 'CONT', $receiverpid; diff --git a/src/test/recovery/t/033_replay_tsp_drops.pl b/src/test/recovery/t/033_replay_tsp_drops.pl index 93c89550511..f9e5c990bcb 100644 --- a/src/test/recovery/t/033_replay_tsp_drops.pl +++ b/src/test/recovery/t/033_replay_tsp_drops.pl @@ -130,16 +130,10 @@ $node_primary->safe_psql( # Standby should fail and should not silently skip replaying the wal # In this test, PANIC turns into WARNING by allow_in_place_tablespaces. # Check the log messages instead of confirming standby failure. -my $max_attempts = $PostgreSQL::Test::Utils::timeout_default * 10; -while ($max_attempts-- >= 0) -{ - last - if ( - $node_standby->log_contains( - qr!WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/!, - $logstart)); - usleep(100_000); -} -ok($max_attempts > 0, "invalid directory creation is detected"); +ok( + $node_standby->wait_for_log( + qr!WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/!, + $logstart), + "invalid directory creation is detected"); done_testing(); diff --git a/src/test/recovery/t/041_checkpoint_at_promote.pl b/src/test/recovery/t/041_checkpoint_at_promote.pl index d0783fef9ae..932647e35d5 100644 --- a/src/test/recovery/t/041_checkpoint_at_promote.pl +++ b/src/test/recovery/t/041_checkpoint_at_promote.pl @@ -107,17 +107,8 @@ $node_standby->safe_psql('postgres', # Wait until the previous restart point completes on the newly-promoted # standby, checking the logs for that. -my $checkpoint_complete = 0; -foreach my $i (0 .. 10 * $PostgreSQL::Test::Utils::timeout_default) -{ - if ($node_standby->log_contains("restartpoint complete", $logstart)) - { - $checkpoint_complete = 1; - last; - } - usleep(100_000); -} -is($checkpoint_complete, 1, 'restart point has completed'); +ok($node_standby->wait_for_log("restartpoint complete", $logstart), + 'restart point has completed'); # Kill with SIGKILL, forcing all the backends to restart. my $psql_timeout = IPC::Run::timer(3600); -- 2.43.0