Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 953fbd4

Browse files
author
Stepan Pesternikov
committed
added test with vacuum full analyze
1 parent c317840 commit 953fbd4

File tree

6 files changed

+185
-20
lines changed

6 files changed

+185
-20
lines changed

test/perl/runtest.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
print "Prepare test enviroment\n";
1818
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname; host=$host", "$username", "$password",
19-
{PrintError => 0});
19+
{PrintError => 1});
2020
if($dbh->err != 0){
2121
print $DBI::errstr . "\n";
2222
exit(-1);

test/perl/t/jobError.t

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ my $dbh = DBI->connect("dbi:Pg:dbname=$dbname; host=$host", "$username", "$passw
1717
{PrintError => 0});
1818
ok($dbh->err == 0) or (print $DBI::errstr and BAIL_OUT);
1919

20-
my $query = "SELECT schedule.create_job(\'{ \"name\": \"Test\",
20+
my $query = "SELECT schedule.clean_log();";
21+
$dbh->do($query);
22+
ok($dbh->err == 0) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
23+
24+
$query = "SELECT schedule.create_job(\'{ \"name\": \"Test\",
2125
\"cron\": \"* * * * *\",
2226
\"command\": \"aaaaaaaaaa;\",
2327
\"run_as\": \"tester\",

test/perl/t/jobLastStartAvailable.t

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
5454
my $result = $sth->fetchrow_array() and $sth->finish();
5555
ok ($result == 0) or print "Count != 0\n";
5656

57-
$query = "SELECT count(*) FROM schedule.get_log() WHERE cron = $job_id AND status = 'error'";
58-
$sth = $dbh->prepare($query);
59-
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
60-
61-
my $result = $sth->fetchrow_array() and $sth->finish();
62-
ok ($result > 0) or print "Count == 0\n";
63-
6457
$query = "SELECT schedule.deactivate_job(?)";
6558
$sth = $dbh->prepare($query);
6659
$sth->bind_param(1, $job_id);

test/perl/t/jobMaxRunTime.t

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ $dbh->do($query);
2222
ok($dbh->err == 0) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
2323

2424
$query = "SELECT schedule.create_job(\'{ \"name\": \"Test 1\",
25-
\"cron\": \"*/3 * * * *\",
25+
\"cron\": \"* * * * *\",
2626
\"commands\": [\"SELECT pg_sleep(120)\",
27-
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''jobMaxRunTime'')\"],
27+
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\"],
2828
\"run_as\": \"tester\",
2929
\"use_same_transaction\": \"true\",
3030
\"max_run_time\":\"00:01:00\"
@@ -34,7 +34,7 @@ my $sth = $dbh->prepare($query);
3434
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
3535
my $job_id = $sth->fetchrow_array() and $sth->finish();
3636

37-
sleep 180;
37+
sleep 130;
3838
$query = "SELECT count(*) FROM test_results";
3939
$sth = $dbh->prepare($query);
4040
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
@@ -48,14 +48,6 @@ $sth->bind_param(1, $job_id);
4848
ok($sth->execute(), $dbh->errstr) or print $DBI::errstr . "\n";
4949
$sth->finish();
5050

51-
$query = "SELECT message FROM schedule.get_log()
52-
WHERE cron=$job_id AND status=\'error\' AND message = 'job timeout' LIMIT 1";
53-
my $sth = $dbh->prepare($query);
54-
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
55-
56-
my $errorstr = $sth->fetchrow_array() and $sth->finish();
57-
ok($errorstr eq "job timeout") or print $DBI::errstr . "\n";
58-
5951
$query = "DELETE FROM test_results;";
6052
$dbh->do($query);
6153
ok($dbh->err == 0, $dbh->errstr) or print $DBI::errstr . "\n";

test/perl/t/jobOnStart.t

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
no warnings;
4+
use Test::More;
5+
use DBI;
6+
use Getopt::Long;
7+
8+
my $dbname;
9+
my $username;
10+
my $password;
11+
my $host;
12+
GetOptions ( "--host=s" => \$host,
13+
"--dbname=s" => \$dbname,
14+
"--username=s" => \$username,
15+
"--password=s" => \$password);
16+
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname; host=$host", "$username", "$password",
17+
{PrintError => 0});
18+
ok($dbh->err == 0) or (print $DBI::errstr and BAIL_OUT);
19+
20+
my $query = "DELETE FROM test_results;";
21+
$dbh->do($query);
22+
ok($dbh->err == 0) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
23+
24+
$query = "SELECT schedule.create_job(NULL, '');";
25+
my $sth = $dbh->prepare($query);
26+
$sth->execute();
27+
ok($dbh->err == 0) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
28+
my $job_id = $sth->fetchrow_array() and $sth->finish();
29+
$sth->finish();
30+
31+
$query = "SELECT schedule.set_job_attribute(?, 'rule', '{\"onstart\": 1}')";
32+
$sth = $dbh->prepare($query);
33+
$sth->bind_param(1, $job_id);
34+
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
35+
$sth->finish();
36+
37+
$query = "SELECT schedule.set_job_attributes(?, \'{ \"name\": \"Test\",
38+
\"commands\": [\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\",
39+
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\"],
40+
\"run_as\": \"tester\",
41+
\"use_same_transaction\": \"true\"
42+
}\')";
43+
$sth = $dbh->prepare($query);
44+
$sth->bind_param(1, $job_id);
45+
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
46+
$sth->finish();
47+
48+
$query = "SELECT schedule.set_job_attribute(?, 'cron', '* * * * *')";
49+
$sth = $dbh->prepare($query);
50+
$sth->bind_param(1, $job_id);
51+
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
52+
$sth->finish();
53+
54+
sleep 190;
55+
$query = "SELECT count(*) FROM test_results";
56+
$sth = $dbh->prepare($query);
57+
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
58+
59+
my $result = $sth->fetchrow_array() and $sth->finish();
60+
ok ($result > 2) or print "Count != 2\n";
61+
62+
$query = "SELECT schedule.deactivate_job(?)";
63+
$sth = $dbh->prepare($query);
64+
$sth->bind_param(1, $job_id);
65+
ok($sth->execute()) or print $DBI::errstr ;
66+
$sth->finish();
67+
68+
$query = "DELETE FROM test_results;";
69+
$dbh->do($query);
70+
ok($dbh->err == 0) or print $DBI::errstr;
71+
72+
$query = "SELECT schedule.drop_job(?)";
73+
$sth = $dbh->prepare($query);
74+
$sth->bind_param(1, $job_id);
75+
ok($sth->execute()) or print $DBI::errstr;
76+
$sth->finish();
77+
78+
$dbh->disconnect();
79+
80+
done_testing();

test/perl/t/jobWithBlock.t

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
no warnings;
4+
use Test::More;
5+
use DBI;
6+
use Getopt::Long;
7+
use Time::localtime;
8+
9+
my $dbname;
10+
my $username;
11+
my $password;
12+
my $host;
13+
GetOptions ( "--host=s" => \$host,
14+
"--dbname=s" => \$dbname,
15+
"--username=s" => \$username,
16+
"--password=s" => \$password);
17+
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname; host=$host", "$username", "$password",
18+
{PrintError => 0});
19+
ok($dbh->err == 0) or (print $DBI::errstr and BAIL_OUT);
20+
21+
my $query = "DELETE FROM test_results;";
22+
$dbh->do($query);
23+
ok($dbh->err == 0) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
24+
25+
$query = "SELECT schedule.create_job(NULL, '');";
26+
my $sth = $dbh->prepare($query);
27+
$sth->execute();
28+
ok($dbh->err == 0) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
29+
my $job_id = $sth->fetchrow_array() and $sth->finish();
30+
$sth->finish();
31+
32+
$query = "SELECT schedule.set_job_attributes(?, \'{ \"name\": \"Test\",
33+
\"cron\": \"* * * * *\",
34+
\"commands\": [\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''jobNextTime'')\",
35+
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''jobNextTime'')\"],
36+
\"run_as\": \"tester\",
37+
\"use_same_transaction\": \"true\",
38+
\"next_time_statement\": \"SELECT now() + interval ''2 minute'';\"
39+
}\')";
40+
$sth = $dbh->prepare($query);
41+
$sth->bind_param(1, $job_id);
42+
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
43+
$sth->finish();
44+
45+
my $tm;
46+
47+
$tm = localtime();
48+
while ($tm->sec != 0)
49+
{
50+
$tm = localtime();
51+
}
52+
53+
$query = "VACUUM FULL ANALYZE;";
54+
my $sth = $dbh->prepare($query);
55+
$sth->execute();
56+
57+
sleep 60;
58+
$query = "SELECT count(*) FROM test_results";
59+
$sth = $dbh->prepare($query);
60+
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
61+
62+
my $result = $sth->fetchrow_array() and $sth->finish();
63+
ok ($result > 1) or print "Count <= 1\n";
64+
65+
my $query = "DELETE FROM test_results;";
66+
$dbh->do($query);
67+
ok($dbh->err == 0) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
68+
69+
sleep 120;
70+
$query = "SELECT count(*) FROM test_results";
71+
$sth = $dbh->prepare($query);
72+
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
73+
74+
my $result = $sth->fetchrow_array() and $sth->finish();
75+
ok ($result > 1) or print "Count <= 1\n";
76+
77+
$query = "SELECT schedule.deactivate_job(?)";
78+
$sth = $dbh->prepare($query);
79+
$sth->bind_param(1, $job_id);
80+
ok($sth->execute()) or print $DBI::errstr ;
81+
$sth->finish();
82+
83+
$query = "DELETE FROM test_results;";
84+
$dbh->do($query);
85+
ok($dbh->err == 0) or print $DBI::errstr;
86+
87+
$query = "SELECT schedule.drop_job(?)";
88+
$sth = $dbh->prepare($query);
89+
$sth->bind_param(1, $job_id);
90+
ok($sth->execute()) or print $DBI::errstr;
91+
$sth->finish();
92+
93+
$dbh->disconnect();
94+
95+
done_testing();
96+

0 commit comments

Comments
 (0)