|
5 | 5 | use warnings;
|
6 | 6 | use TestLib;
|
7 | 7 | use PostgresNode;
|
8 |
| -use Test::More tests => 19; |
| 8 | +use Test::More tests => 27; |
9 | 9 |
|
10 | 10 | program_help_ok('pg_receivewal');
|
11 | 11 | program_version_ok('pg_receivewal');
|
|
58 | 58 | $primary->psql('postgres',
|
59 | 59 | 'INSERT INTO test_table VALUES (generate_series(1,100));');
|
60 | 60 |
|
61 |
| -# Stream up to the given position. |
| 61 | +# Stream up to the given position. This is necessary to have a fixed |
| 62 | +# started point for the next commands done in this test, with or without |
| 63 | +# compression involved. |
62 | 64 | $primary->command_ok(
|
63 | 65 | [
|
64 | 66 | 'pg_receivewal', '-D', $stream_dir, '--verbose',
|
65 | 67 | '--endpos', $nextlsn, '--synchronous', '--no-loop'
|
66 | 68 | ],
|
67 | 69 | 'streaming some WAL with --synchronous');
|
68 | 70 |
|
| 71 | +# Verify that one partial file was generated and keep track of it |
| 72 | +my @partial_wals = glob "$stream_dir/*\.partial"; |
| 73 | +is(scalar(@partial_wals), 1, "one partial WAL segment was created"); |
| 74 | + |
| 75 | +# Check ZLIB compression if available. |
| 76 | +SKIP: |
| 77 | +{ |
| 78 | + skip "postgres was not built with ZLIB support", 5 |
| 79 | + if (!check_pg_config("#define HAVE_LIBZ 1")); |
| 80 | + |
| 81 | + # Generate more WAL worth one completed, compressed, segment. |
| 82 | + $primary->psql('postgres', 'SELECT pg_switch_wal();'); |
| 83 | + $nextlsn = |
| 84 | + $primary->safe_psql('postgres', 'SELECT pg_current_wal_insert_lsn();'); |
| 85 | + chomp($nextlsn); |
| 86 | + $primary->psql('postgres', |
| 87 | + 'INSERT INTO test_table VALUES (generate_series(100,200));'); |
| 88 | + |
| 89 | + $primary->command_ok( |
| 90 | + [ |
| 91 | + 'pg_receivewal', '-D', $stream_dir, '--verbose', |
| 92 | + '--endpos', $nextlsn, '--compress', '1' |
| 93 | + ], |
| 94 | + "streaming some WAL using ZLIB compression"); |
| 95 | + |
| 96 | + # Verify that the stored files are generated with their expected |
| 97 | + # names. |
| 98 | + my @zlib_wals = glob "$stream_dir/*.gz"; |
| 99 | + is(scalar(@zlib_wals), 1, |
| 100 | + "one WAL segment compressed with ZLIB was created"); |
| 101 | + my @zlib_partial_wals = glob "$stream_dir/*.gz.partial"; |
| 102 | + is(scalar(@zlib_partial_wals), |
| 103 | + 1, "one partial WAL segment compressed with ZLIB was created"); |
| 104 | + |
| 105 | + # Verify that the start streaming position is computed correctly by |
| 106 | + # comparing it with the partial file generated previously. The name |
| 107 | + # of the previous partial, now-completed WAL segment is updated, keeping |
| 108 | + # its base number. |
| 109 | + $partial_wals[0] =~ s/\.partial$/.gz/; |
| 110 | + is($zlib_wals[0] =~ m/$partial_wals[0]/, |
| 111 | + 1, "one partial WAL segment is now completed"); |
| 112 | + # Update the list of partial wals with the current one. |
| 113 | + @partial_wals = @zlib_partial_wals; |
| 114 | + |
| 115 | + # There is one complete and one partial file compressed with ZLIB. |
| 116 | + # Check the integrity of both, if gzip is a command available. |
| 117 | + my $gzip = $ENV{GZIP_PROGRAM}; |
| 118 | + skip "program gzip is not found in your system", 1 |
| 119 | + if ( !defined $gzip |
| 120 | + || $gzip eq '' |
| 121 | + || system_log($gzip, '--version') != 0); |
| 122 | + |
| 123 | + push(@zlib_wals, @zlib_partial_wals); |
| 124 | + my $gzip_is_valid = system_log($gzip, '--test', @zlib_wals); |
| 125 | + is($gzip_is_valid, 0, |
| 126 | + "gzip verified the integrity of compressed WAL segments"); |
| 127 | +} |
| 128 | + |
| 129 | +# Verify that the start streaming position is computed and that the value is |
| 130 | +# correct regardless of whether ZLIB is available. |
| 131 | +$primary->psql('postgres', 'SELECT pg_switch_wal();'); |
| 132 | +$nextlsn = |
| 133 | + $primary->safe_psql('postgres', 'SELECT pg_current_wal_insert_lsn();'); |
| 134 | +chomp($nextlsn); |
| 135 | +$primary->psql('postgres', |
| 136 | + 'INSERT INTO test_table VALUES (generate_series(200,300));'); |
| 137 | +$primary->command_ok( |
| 138 | + [ 'pg_receivewal', '-D', $stream_dir, '--verbose', '--endpos', $nextlsn ], |
| 139 | + "streaming some WAL"); |
| 140 | + |
| 141 | +$partial_wals[0] =~ s/(\.gz)?.partial//; |
| 142 | +ok(-e $partial_wals[0], "check that previously partial WAL is now complete"); |
| 143 | + |
69 | 144 | # Permissions on WAL files should be default
|
70 | 145 | SKIP:
|
71 | 146 | {
|
|
0 commit comments