On Mon, Mar 15, 2021 at 03:50:48PM +0000, Jacob Champion wrote:
>               # might need to retry if logging collector process is slow...
>               my $max_attempts = 180 * 10;
>               my $first_logfile;
>               for (my $attempts = 0; $attempts < $max_attempts; $attempts++)
>               {
>                       $first_logfile = slurp_file($node->data_dir . '/' . 
> $lfname);
> -                     last if $first_logfile =~ m/\Q$expect_log_msg\E/;
> +
> +                     # Don't include previously matched text in the search.
> +                     $first_logfile = substr $first_logfile, 
> $current_log_position;
> +                     if ($first_logfile =~ m/\Q$expect_log_msg\E/g)
> +                     {
> +                             $current_log_position += pos($first_logfile);
> +                             last;
> +                     }
> +
>                       usleep(100_000);

Looking at 0001, I am not much a fan of relying on the position of the
matching pattern in the log file.  Instead of relying on the logging
collector and one single file, why not just changing the generation of
the logfile and rely on the output of stderr by restarting the server?
That means less tests, no need to wait for the logging collector to do
its business, and it solves your problem.  Please see the idea with
the patch attached.  Thoughts?
--
Michael
diff --git a/src/test/kerberos/t/001_auth.pl b/src/test/kerberos/t/001_auth.pl
index 079321bbfc..aca673e97a 100644
--- a/src/test/kerberos/t/001_auth.pl
+++ b/src/test/kerberos/t/001_auth.pl
@@ -20,7 +20,7 @@ use Time::HiRes qw(usleep);
 
 if ($ENV{with_gssapi} eq 'yes')
 {
-	plan tests => 34;
+	plan tests => 26;
 }
 else
 {
@@ -170,7 +170,6 @@ $node->append_conf(
 	'postgresql.conf', qq{
 listen_addresses = '$hostaddr'
 krb_server_keyfile = '$keytab'
-logging_collector = on
 log_connections = on
 # these ensure stability of test results:
 log_rotation_age = 0
@@ -212,27 +211,13 @@ sub test_access
 	# Verify specified log message is logged in the log file.
 	if ($expect_log_msg ne '')
 	{
-		my $current_logfiles = slurp_file($node->data_dir . '/current_logfiles');
-		note "current_logfiles = $current_logfiles";
-		like($current_logfiles, qr|^stderr log/postgresql-.*log$|,
-			 'current_logfiles is sane');
-
-		my $lfname = $current_logfiles;
-		$lfname =~ s/^stderr //;
-		chomp $lfname;
-
-		# might need to retry if logging collector process is slow...
-		my $max_attempts = 180 * 10;
-		my $first_logfile;
-		for (my $attempts = 0; $attempts < $max_attempts; $attempts++)
-		{
-			$first_logfile = slurp_file($node->data_dir . '/' . $lfname);
-			last if $first_logfile =~ m/\Q$expect_log_msg\E/;
-			usleep(100_000);
-		}
-
+		my $first_logfile = slurp_file($node->logfile);
 		like($first_logfile, qr/\Q$expect_log_msg\E/,
-			 'found expected log file content');
+		     'found expected log file content');
+
+		# Rotate to a new file, for any follow-up check.
+		$node->rotate_logfile;
+		$node->restart;
 	}
 
 	return;

Attachment: signature.asc
Description: PGP signature

Reply via email to