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

Commit 31494f6

Browse files
author
Vladimir Ershov
committed
fix tests
1 parent 195d596 commit 31494f6

File tree

8 files changed

+86
-23
lines changed

8 files changed

+86
-23
lines changed

test/perl/runtest.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
);
110110
my $harness = TAP::Harness->new( \%args );
111111
my @tests = glob( 't/*.t' );
112-
## @tests = ('t/jobNextTime.t'); - PGPROEE10 тут валится
112+
@tests = ('t/jobMaxRunTime.t');
113113
$harness->runtests(@tests);
114114

115115

test/perl/t/_json.pm

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package t;
2+
3+
use strict;
4+
5+
sub json
6+
{
7+
my $data = shift;
8+
9+
return _element($data);
10+
}
11+
12+
sub _escape
13+
{
14+
my $str = shift;
15+
16+
$str =~ s/"/\\"/g;
17+
return $str;
18+
}
19+
20+
sub _element
21+
{
22+
my $data = shift;
23+
24+
if(ref($data) eq 'HASH')
25+
{
26+
my @out;
27+
foreach my $name (keys %$data)
28+
{
29+
push @out, q["]._escape($name).q[":]._element($data->{$name});
30+
}
31+
32+
return "{".join(', ', @out)."}";
33+
}
34+
elsif(ref($data) eq 'ARRAY')
35+
{
36+
return "[".join(', ', map { _element($_) } @$data)."]";
37+
}
38+
else
39+
{
40+
return q["]._escape($data).q["];
41+
}
42+
}
43+
44+
1;

test/perl/t/activateJob.t

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use Test::More;
55
use DBI;
66
use Getopt::Long;
77

8+
require 't/_json.pm';
89
my $dbh = require 't/_connect.pl';
910
ok($dbh->err == 0) or (print $DBI::errstr and BAIL_OUT);
1011

@@ -25,13 +26,18 @@ $sth->bind_param(1, $job_id);
2526
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
2627
$sth->finish();
2728

28-
$query = "SELECT schedule.set_job_attributes(?, \'{ \"name\": \"Test\",
29-
\"cron\": \"* * * * *\",
30-
\"commands\": [\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\",
31-
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\"],
32-
\"run_as\": \"tester\",
33-
\"use_same_transaction\": \"true\"
34-
}\')";
29+
my %data = (
30+
name => "Test activateJob.t",
31+
cron => "* * * * *",
32+
commands => [
33+
"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')",
34+
"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')"
35+
],
36+
run_as => "tester",
37+
use_same_transaction => "true"
38+
);
39+
40+
$query = "SELECT schedule.set_job_attributes(?, '". t::json(\%data) ."')";
3541
$sth = $dbh->prepare($query);
3642
$sth->bind_param(1, $job_id);
3743
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);

test/perl/t/createJobWithJsonb.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ ok($dbh->err == 0) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL
1414

1515
$query = "SELECT schedule.create_job(\'{ \"name\": \"Test 1\",
1616
\"cron\": \"* * * * *\",
17-
\"commands\": [\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\",
18-
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\"],
17+
\"commands\": [\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithJsonb'')\",
18+
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithJsonb'')\"],
1919
\"run_as\": \"tester\",
2020
\"use_same_transaction\": \"true\"
2121
}\'

test/perl/t/createSimpleJobWithDates.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ok($dbh->err == 0, $dbh->errstr) or (print $DBI::errstr . "\n" and $dbh->disconn
1414

1515
$query = "SELECT schedule.create_job(ARRAY[(now() + interval \'1 minute\')::timestamp with time zone,
1616
(now() + interval \'2 minute\')::timestamp with time zone],
17-
\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createSimpleJobWithDate'')\');";
17+
\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createSimpleJobWithDates'')\');";
1818
my $sth = $dbh->prepare($query);
1919
ok($sth->execute(), $dbh->errstr) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
2020
my $job_id = $sth->fetchrow_array() and $sth->finish();

test/perl/t/createSimpleJobWithJsonb.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ok($dbh->err == 0) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL
1414

1515
$query = "SELECT schedule.create_job(\'{ \"name\": \"Test 1\",
1616
\"cron\": \"* * * * *\",
17-
\"command\": \"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createSimpleJob'')\",
17+
\"command\": \"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createSimpleJobWithJsonb'')\",
1818
\"run_as\": \"tester\"
1919
}\'
2020
);";

test/perl/t/jobExecuteWindow.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ $sth->finish();
3434

3535
$query = "SELECT schedule.set_job_attributes(?, \'{ \"name\": \"Test\",
3636
\"cron\": \"* * * * *\",
37-
\"commands\": [\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\",
38-
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\"],
37+
\"commands\": [\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''jobExecuteWindow'')\",
38+
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''jobExecuteWindow'')\"],
3939
\"run_as\": \"tester\",
4040
\"use_same_transaction\": \"true\"
4141
}\')";

test/perl/t/jobMaxRunTime.t

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,34 @@ no warnings;
44
use Test::More;
55
use DBI;
66
use Getopt::Long;
7+
use Data::Dumper;
78

9+
require 't/_json.pm';
810
my $dbh = require 't/_connect.pl';
911
ok($dbh->err == 0) or (print $DBI::errstr and BAIL_OUT);
1012

1113
my $query = "DELETE FROM test_results;";
1214
$dbh->do($query);
1315
ok($dbh->err == 0) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
1416

15-
$query = "SELECT schedule.create_job(\'{ \"name\": \"Test 1\",
16-
\"cron\": \"* * * * *\",
17-
\"commands\": [\"SELECT pg_sleep(120)\",
18-
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\"],
19-
\"run_as\": \"tester\",
20-
\"use_same_transaction\": \"true\",
21-
\"max_run_time\":\"00:01:00\"
22-
}\'
23-
);";
17+
my %data = (
18+
name => "Test 1",
19+
cron => "* * * * *",
20+
commands => [
21+
"SELECT pg_sleep(120)",
22+
"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createjobMaxRunTime'')"
23+
],
24+
run_as => "tester",
25+
use_same_transaction => "true",
26+
max_run_time => "00:01:00"
27+
);
28+
29+
$query = q[SELECT schedule.create_job('].t::json(\%data).q[')];
2430
my $sth = $dbh->prepare($query);
2531
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
2632
my $job_id = $sth->fetchrow_array() and $sth->finish();
2733

34+
2835
sleep 130;
2936
$query = "SELECT count(*) FROM test_results";
3037
$sth = $dbh->prepare($query);
@@ -33,6 +40,12 @@ ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAI
3340
my $result = $sth->fetchrow_array() and $sth->finish();
3441
ok ($result == 0) or print "Count $result != 0\n";
3542

43+
if($result != 0)
44+
{
45+
my $data = $dbh->selectall_arrayref('select * from test_results', { Slice => {} });
46+
print Data::Dumper::Dumper($data);
47+
}
48+
3649
$query = "SELECT schedule.deactivate_job(?)";
3750
$sth = $dbh->prepare($query);
3851
$sth->bind_param(1, $job_id);

0 commit comments

Comments
 (0)