|
6 | 6 |
|
7 | 7 | use PostgresNode;
|
8 | 8 | use TestLib;
|
9 |
| -use Test::Moretests=>5; |
| 9 | +use Test::Moretests=>10; |
10 | 10 | use Time::HiResqw(usleep);
|
11 | 11 |
|
| 12 | +# Extract the file name of a $format from the contents of |
| 13 | +# current_logfiles. |
| 14 | +subfetch_file_name |
| 15 | +{ |
| 16 | +my$logfiles =shift; |
| 17 | +my$format =shift; |
| 18 | +my@lines =split(/\n/,$logfiles); |
| 19 | +my$filename =undef; |
| 20 | +foreachmy$line (@lines) |
| 21 | +{ |
| 22 | +if ($line =~/$format (.*)$/gm) |
| 23 | +{ |
| 24 | +$filename =$1; |
| 25 | +} |
| 26 | +} |
| 27 | + |
| 28 | +return$filename; |
| 29 | +} |
| 30 | + |
| 31 | +# Check for a pattern in the logs associated to one format. |
| 32 | +subcheck_log_pattern |
| 33 | +{ |
| 34 | +my$format =shift; |
| 35 | +my$logfiles =shift; |
| 36 | +my$pattern =shift; |
| 37 | +my$node =shift; |
| 38 | +my$lfname = fetch_file_name($logfiles,$format); |
| 39 | + |
| 40 | +my$max_attempts = 180 * 10; |
| 41 | + |
| 42 | +my$logcontents; |
| 43 | +for (my$attempts = 0;$attempts <$max_attempts;$attempts++) |
| 44 | +{ |
| 45 | +$logcontents = slurp_file($node->data_dir .'/' .$lfname); |
| 46 | +lastif$logcontents =~m/$pattern/; |
| 47 | +usleep(100_000); |
| 48 | +} |
| 49 | + |
| 50 | +like($logcontents,qr/$pattern/, |
| 51 | +"found expected log file content for$format"); |
| 52 | + |
| 53 | +# While we're at it, test pg_current_logfile() function |
| 54 | +is($node->safe_psql('postgres',"SELECT pg_current_logfile('$format')"), |
| 55 | +$lfname, |
| 56 | +"pg_current_logfile() gives correct answer with$format"); |
| 57 | +return; |
| 58 | +} |
| 59 | + |
12 | 60 | # Set up node with logging collector
|
13 | 61 | my$node = PostgresNode->new('primary');
|
14 | 62 | $node->init();
|
15 | 63 | $node->append_conf(
|
16 | 64 | 'postgresql.conf',qq(
|
17 | 65 | logging_collector = on
|
| 66 | +log_destination = 'stderr, csvlog' |
18 | 67 | # these ensure stability of test results:
|
19 | 68 | log_rotation_age = 0
|
20 | 69 | lc_messages = 'C'
|
|
44 | 93 |
|
45 | 94 | like(
|
46 | 95 | $current_logfiles,
|
47 |
| -qr|^stderr log/postgresql-.*log$|, |
| 96 | +qr|^stderr log/postgresql-.*log |
| 97 | +csvlog log/postgresql-.*csv$|, |
48 | 98 | 'current_logfiles is sane');
|
49 | 99 |
|
50 |
| -my$lfname =$current_logfiles; |
51 |
| -$lfname =~s/^stderr//; |
52 |
| -chomp$lfname; |
53 |
| - |
54 |
| -my$first_logfile; |
55 |
| -for (my$attempts = 0;$attempts <$max_attempts;$attempts++) |
56 |
| -{ |
57 |
| -$first_logfile = slurp_file($node->data_dir .'/' .$lfname); |
58 |
| -lastif$first_logfile =~m/division by zero/; |
59 |
| -usleep(100_000); |
60 |
| -} |
61 |
| - |
62 |
| -like($first_logfile,qr/division by zero/,'found expected log file content'); |
63 |
| - |
64 |
| -# While we're at it, test pg_current_logfile() function |
65 |
| -is($node->safe_psql('postgres',"SELECT pg_current_logfile('stderr')"), |
66 |
| -$lfname,'pg_current_logfile() gives correct answer'); |
| 100 | +check_log_pattern('stderr',$current_logfiles,'division by zero',$node); |
| 101 | +check_log_pattern('csvlog',$current_logfiles,'division by zero',$node); |
67 | 102 |
|
68 | 103 | # Sleep 2 seconds and ask for log rotation; this should result in
|
69 | 104 | # output into a different log file name.
|
|
84 | 119 |
|
85 | 120 | like(
|
86 | 121 | $new_current_logfiles,
|
87 |
| -qr|^stderr log/postgresql-.*log$|, |
| 122 | +qr|^stderr log/postgresql-.*log |
| 123 | +csvlog log/postgresql-.*csv$|, |
88 | 124 | 'new current_logfiles is sane');
|
89 | 125 |
|
90 |
| -$lfname =$new_current_logfiles; |
91 |
| -$lfname =~s/^stderr//; |
92 |
| -chomp$lfname; |
93 |
| - |
94 | 126 | # Verify that log output gets to this file, too
|
95 |
| - |
96 | 127 | $node->psql('postgres','fee fi fo fum');
|
97 | 128 |
|
98 |
| -my$second_logfile; |
99 |
| -for (my$attempts = 0;$attempts <$max_attempts;$attempts++) |
100 |
| -{ |
101 |
| -$second_logfile = slurp_file($node->data_dir .'/' .$lfname); |
102 |
| -lastif$second_logfile =~m/syntax error/; |
103 |
| -usleep(100_000); |
104 |
| -} |
105 |
| - |
106 |
| -like( |
107 |
| -$second_logfile, |
108 |
| -qr/syntax error/, |
109 |
| -'found expected log file content in new log file'); |
| 129 | +check_log_pattern('stderr',$new_current_logfiles,'syntax error',$node); |
| 130 | +check_log_pattern('csvlog',$new_current_logfiles,'syntax error',$node); |
110 | 131 |
|
111 | 132 | $node->stop();
|