Skip to content

Commit 77cf131

Browse files
author
Stepan Pesternikov
committed
added 2 tests
1 parent a0093a7 commit 77cf131

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

test/perl/t/jobMaxInstances.t

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 . "\n" and $dbh->disconnect() and BAIL_OUT);
23+
24+
$query = "SELECT schedule.create_job(\'{ \"name\": \"Test 1\",
25+
\"cron\": \"* * * * *\",
26+
\"commands\": [\"SELECT pg_sleep(120)\",
27+
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''jobMaxInstances'')\"],
28+
\"run_as\": \"tester\",
29+
\"use_same_transaction\": \"true\",
30+
\"max_instances\": 1
31+
}\'
32+
);";
33+
my $sth = $dbh->prepare($query);
34+
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
35+
my $job_id = $sth->fetchrow_array() and $sth->finish();
36+
37+
sleep 120;
38+
$query = "SELECT schedule.deactivate_job(?)";
39+
$sth = $dbh->prepare($query);
40+
$sth->bind_param(1, $job_id);
41+
ok($sth->execute(), $dbh->errstr) or print $DBI::errstr . "\n";
42+
$sth->finish();
43+
44+
$query = "SELECT message FROM schedule.get_log() WHERE cron=$job_id AND status=\'error\' ORDER BY cron DESC LIMIT 1";
45+
my $sth = $dbh->prepare($query);
46+
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
47+
my $errorstr = $sth->fetchrow_array() and $sth->finish();
48+
ok($errorstr eq "max instances limit reached") or print $DBI::errstr . "\n";
49+
50+
$query = "DELETE FROM test_results;";
51+
$dbh->do($query);
52+
ok($dbh->err == 0, $dbh->errstr) or print $DBI::errstr . "\n";
53+
54+
$query = "SELECT schedule.drop_job(?)";
55+
$sth = $dbh->prepare($query);
56+
$sth->bind_param(1, $job_id);
57+
ok($sth->execute(), $dbh->errstr) or print $DBI::errstr . "\n";
58+
$sth->finish();
59+
60+
$dbh->disconnect();
61+
62+
done_testing();
63+

test/perl/t/submitJobWithError.t

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 . "\n" and $dbh->disconnect() and BAIL_OUT);
23+
24+
$query = "SELECT schedule.submit_job(\'SELECT * FROM test1\');";
25+
my $sth = $dbh->prepare($query);
26+
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
27+
my $job_id = $sth->fetchrow_array() and $sth->finish();
28+
29+
sleep 30;
30+
$query = "SELECT error FROM schedule.all_job_status WHERE id=$job_id";
31+
my $sth = $dbh->prepare($query);
32+
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
33+
34+
my $errorstr = $sth->fetchrow_array() and $sth->finish();
35+
ok($errorstr eq "relation \"test1\" does not exist") or print $DBI::errstr . "\n";
36+
37+
$dbh->disconnect();
38+
39+
done_testing();
40+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy