v3-0002-pg_waldump-Add-test-case-for-notice-message.patch
text/plain
Filename: v3-0002-pg_waldump-Add-test-case-for-notice-message.patch
Type: text/plain
Part: 1
Patch
Format: format-patch
Series: patch v3-0002
Subject: pg_waldump: Add test case for notice message
| File | + | − |
|---|---|---|
| src/bin/pg_waldump/pg_waldump.c | 6 | 6 |
| src/bin/pg_waldump/t/001_basic.pl | 18 | 0 |
From 86a7f0ca489b61907973a266f0b5855869b30692 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 28 Jun 2023 07:28:14 +0200
Subject: [PATCH v3 2/2] pg_waldump: Add test case for notice message
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.
---
src/bin/pg_waldump/pg_waldump.c | 12 ++++++------
src/bin/pg_waldump/t/001_basic.pl | 18 ++++++++++++++++++
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c
index c6d3ae6344..6e53b94219 100644
--- a/src/bin/pg_waldump/pg_waldump.c
+++ b/src/bin/pg_waldump/pg_waldump.c
@@ -1219,12 +1219,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;
diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl
index d4056e1b95..4bf73b2e34 100644
--- a/src/bin/pg_waldump/t/001_basic.pl
+++ b/src/bin/pg_waldump/t/001_basic.pl
@@ -149,6 +149,24 @@
command_ok([ 'pg_waldump', '-p', $node->data_dir, '--start', $start_lsn, '--end', $end_lsn ], 'runs with path option and start and end locations');
command_fails_like([ 'pg_waldump', '-p', $node->data_dir, '--start', $start_lsn ], qr/error: error in WAL record at/, 'falling off the end of the WAL results in an error');
+# 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.
--
2.41.0