Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9d5c22d

Browse files
committed
Improve logrotate test so that it meaningfully exercises syslogger.
Discussion of bug #15804 reveals that this test didn't really provethat the syslogger child process ever launched successfully, muchless did anything. It was only checking that the expected log filegets created, and that's done in the postmaster. Moreover, thetest assumed it could rename the log file, which is likely to failon Windows (cf. commitd611175).Instead, use the default log file name pattern, which should resultin a new file name being chosen after 1 second, and verify thatrotation has occurred by checking for a new file name. Also add codeto test that messages actually do propagate through the syslogger.In theory this version of the test should work on Windows, sorevertd611175.Discussion:https://postgr.es/m/15804-3721117bf40fb654@postgresql.org
1 parent8334515 commit9d5c22d

File tree

1 file changed

+63
-28
lines changed

1 file changed

+63
-28
lines changed

‎src/bin/pg_ctl/t/004_logrotate.pl

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,86 @@
33

44
use PostgresNode;
55
use TestLib;
6-
use Test::More;
6+
use Test::Moretests=> 4;
77
use Time::HiResqw(usleep);
88

9-
if ($windows_os)
10-
{
11-
planskip_all=>'logrotate test not supported on Windows';
12-
exit;
13-
}
14-
else
15-
{
16-
plantests=> 1;
17-
}
18-
19-
20-
my$tempdir = TestLib::tempdir;
21-
9+
# Set up node with logging collector
2210
my$node = get_new_node('primary');
23-
$node->init(allows_streaming=> 1);
11+
$node->init();
2412
$node->append_conf(
2513
'postgresql.conf',qq(
2614
logging_collector = on
27-
log_directory = 'log'
28-
log_filename = 'postgresql.log'
15+
lc_messages = 'C'
2916
));
3017

3118
$node->start();
3219

33-
#Rename log file and rotatelog. Then log file should appear again.
20+
#Verify thatlog output gets to the file
3421

35-
my$logfile =$node->data_dir .'/log/postgresql.log';
36-
my$old_logfile =$node->data_dir .'/log/postgresql.old';
37-
rename($logfile,$old_logfile);
22+
$node->psql('postgres','SELECT 1/0');
3823

39-
$node->logrotate();
24+
my$current_logfiles = slurp_file($node->data_dir .'/current_logfiles');
25+
26+
note"current_logfiles =$current_logfiles";
27+
28+
like($current_logfiles,qr|^stderr log/postgresql-.*log$|,
29+
'current_logfiles is sane');
30+
31+
my$lfname =$current_logfiles;
32+
$lfname =~s/^stderr//;
33+
chomp$lfname;
4034

41-
# pg_ctl logrotate doesn't wait until rotation request being completed. So
42-
# we have to wait some time until log file appears.
43-
my$attempts = 0;
35+
# might need to retry if logging collector process is slow...
4436
my$max_attempts = 180 * 10;
45-
while (not-e$logfileand$attempts <$max_attempts)
37+
38+
my$first_logfile;
39+
for (my$attempts = 0;$attempts <$max_attempts;$attempts++)
40+
{
41+
$first_logfile = slurp_file($node->data_dir .'/' .$lfname);
42+
lastif$first_logfile =~m/division by zero/;
43+
usleep(100_000);
44+
}
45+
46+
like($first_logfile,qr/division by zero/,
47+
'found expected log file content');
48+
49+
# Sleep 2 seconds and ask for log rotation; this should result in
50+
# output into a different log file name.
51+
sleep(2);
52+
$node->logrotate();
53+
54+
# pg_ctl logrotate doesn't wait for rotation request to be completed.
55+
# Allow a bit of time for it to happen.
56+
my$new_current_logfiles;
57+
for (my$attempts = 0;$attempts <$max_attempts;$attempts++)
58+
{
59+
$new_current_logfiles = slurp_file($node->data_dir .'/current_logfiles');
60+
lastif$new_current_logfilesne$current_logfiles;
61+
usleep(100_000);
62+
}
63+
64+
note"now current_logfiles =$new_current_logfiles";
65+
66+
like($new_current_logfiles,qr|^stderr log/postgresql-.*log$|,
67+
'new current_logfiles is sane');
68+
69+
$lfname =$new_current_logfiles;
70+
$lfname =~s/^stderr//;
71+
chomp$lfname;
72+
73+
# Verify that log output gets to this file, too
74+
75+
$node->psql('postgres','fee fi fo fum');
76+
77+
my$second_logfile;
78+
for (my$attempts = 0;$attempts <$max_attempts;$attempts++)
4679
{
80+
$second_logfile = slurp_file($node->data_dir .'/' .$lfname);
81+
lastif$second_logfile =~m/syntax error/;
4782
usleep(100_000);
48-
$attempts++;
4983
}
5084

51-
ok(-e$logfile,"log file exists");
85+
like($second_logfile,qr/syntax error/,
86+
'found expected log file content in new log file');
5287

5388
$node->stop();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp