pg_waldump: Add test case for notice message
authorPeter Eisentraut <[email protected]>
Wed, 5 Jul 2023 08:16:56 +0000 (10:16 +0200)
committerPeter Eisentraut <[email protected]>
Wed, 5 Jul 2023 08:50:16 +0000 (10:50 +0200)
Add a test case for the "first record is after" message.  Also, this
message should really go to stderr, so change to use pg_log_info.

Reviewed-by: Tristen Raab <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CAAcByaKM7zyJSDkPWv6_%2BapupY4fXXM3q3SRXas9MMNVPUGcsQ%40mail.gmail.com

src/bin/pg_waldump/pg_waldump.c
src/bin/pg_waldump/t/001_basic.pl

index 96845e1a1aeb7acca3a13cf6dca27545be0ff23c..e8b5a6cd6175b93416079227b7439dea077115da 100644 (file)
@@ -1220,12 +1220,12 @@ main(int argc, char **argv)
     */
    if (first_record != private.startptr &&
        XLogSegmentOffset(private.startptr, WalSegSz) != 0)
-       printf(ngettext("first record is after %X/%X, at %X/%X, skipping over %u byte\n",
-                       "first record is after %X/%X, at %X/%X, skipping over %u bytes\n",
-                       (first_record - private.startptr)),
-              LSN_FORMAT_ARGS(private.startptr),
-              LSN_FORMAT_ARGS(first_record),
-              (uint32) (first_record - private.startptr));
+       pg_log_info(ngettext("first record is after %X/%X, at %X/%X, skipping over %u byte",
+                            "first record is after %X/%X, at %X/%X, skipping over %u bytes",
+                            (first_record - private.startptr)),
+                   LSN_FORMAT_ARGS(private.startptr),
+                   LSN_FORMAT_ARGS(first_record),
+                   (uint32) (first_record - private.startptr));
 
    if (config.stats == true && !config.quiet)
        stats.startptr = first_record;
index 06201adc4646f7e53b8633a188fb066fdd11da49..029a0d052187fb6b50c604fc0139eb9e93001e45 100644 (file)
@@ -153,6 +153,25 @@ command_like([ 'pg_waldump', '--quiet', $node->data_dir . '/pg_wal/' . $start_wa
 command_fails_like([ 'pg_waldump', '--quiet', '-p', $node->data_dir, '--start', $start_lsn ], qr/error: error in WAL record at/, 'errors are shown with --quiet');
 
 
+# Test for: Display a message that we're skipping data if `from`
+# wasn't a pointer to the start of a record.
+{
+   # Construct a new LSN that is one byte past the original
+   # start_lsn.
+   my ($part1, $part2) = split qr{/}, $start_lsn;
+   my $lsn2 = hex $part2;
+   $lsn2++;
+   my $new_start = sprintf("%s/%X", $part1, $lsn2);
+
+   my (@cmd, $stdout, $stderr, $result);
+
+   @cmd = ( 'pg_waldump', '--start', $new_start, $node->data_dir . '/pg_wal/' . $start_walfile );
+   $result = IPC::Run::run \@cmd, '>', \$stdout, '2>', \$stderr;
+   ok($result, "runs with start segment and start LSN specified");
+   like($stderr, qr/first record is after/, 'info message printed');
+}
+
+
 # Helper function to test various options.  Pass options as arguments.
 # Output lines are returned as array.
 sub test_pg_waldump