Skip to content

Commit 4b3750c

Browse files
committed
Strip whitespace when checking query results in TAP tests
1 parent 08609b8 commit 4b3750c

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

test/perl/TimescaleNode.pm

+15
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,19 @@ sub psql_is
5656
"$testname: psql output check");
5757
}
5858

59+
# remove leading and trailing whitespace
60+
sub strip
61+
{
62+
my ($self, $str) = @_;
63+
$str =~ s/^\s+|\s+$//g;
64+
return $str;
65+
}
66+
67+
sub safe_psql
68+
{
69+
my ($self, $db, $query) = @_;
70+
my $psql_out = $self->SUPER::safe_psql($db, $query);
71+
return $self->strip($psql_out);
72+
}
73+
5974
1;

tsl/test/t/001_job_crash_log.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ END
3838
my $query_add =
3939
q[select add_job('custom_proc_sleep60', '5 minutes', initial_start => now())];
4040
my $jobid = $node->safe_psql('postgres', "$query_add");
41-
is($jobid, '1000', 'job was added');
41+
is($jobid, 1000, 'job was added');
4242

4343
my $query_pid_exists = <<"END_OF_QUERY";
4444
select count(*) from pg_stat_activity

tsl/test/t/004_truncate_or_delete_spin_lock.pl

+2-14
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@
2727
temperature double precision null);
2828
}
2929
);
30-
is($result, '', 'create table');
3130

3231
# Create hypertable
3332
$result = $node->safe_psql(
3433
'postgres', q{
35-
SELECT FROM create_hypertable('sensor_data','time', chunk_time_interval => INTERVAL '1 month');
34+
SELECT table_name FROM create_hypertable('sensor_data','time', chunk_time_interval => INTERVAL '1 month');
3635
}
3736
);
38-
is($result, '', 'create hypertable');
37+
is($result, 'sensor_data', 'create hypertable');
3938

4039
# Insert data
4140
$result = $node->safe_psql(
@@ -52,7 +51,6 @@
5251
ORDER BY time;
5352
}
5453
);
55-
is($result, '', 'insert data');
5654

5755
# Define count query
5856
my $count_query = "SELECT count(*) FROM sensor_data;";
@@ -72,7 +70,6 @@
7270
ALTER TABLE sensor_data SET (timescaledb.compress, timescaledb.compress_segmentby = 'sensor_id');
7371
}
7472
);
75-
is($result, '', 'enable compression');
7673

7774
# Get number of chunks
7875
my $n_chunks = $node->safe_psql(
@@ -87,7 +84,6 @@
8784
# SET session 1 behaviour to `truncate_or_delete`
8885
$result = $s1->query_safe(
8986
"SET timescaledb.compress_truncate_behaviour TO truncate_or_delete;");
90-
isnt($result, '', "session 1: set truncate_or_delete");
9187

9288
# Run tests
9389

@@ -97,10 +93,8 @@
9793

9894
# Begin txns in both sessions
9995
$result = $s1->query_safe("BEGIN");
100-
isnt($result, '', "session 1: begin");
10196

10297
$result = $s2->query_safe("BEGIN");
103-
isnt($result, '', "session 2: begin");
10498

10599
# The aggregation query takes an AccessShareLock on the chunk, preventing truncate
106100
$result = $s2->query_safe($count_query);
@@ -123,7 +117,6 @@
123117
is($result, $num_rows, "session 2: validate row count again");
124118

125119
$result = $s2->query_safe("COMMIT");
126-
isnt($result, '', "session 2: commit");
127120

128121
# No AccessExclusiveLock on the uncompressed chunk
129122
$result = $s1->query_safe(
@@ -134,7 +127,6 @@
134127

135128

136129
$result = $s1->query_safe("ROLLBACK");
137-
isnt($result, '', "session 1: rollback");
138130

139131
##########################################################################
140132

@@ -143,10 +135,8 @@
143135

144136
# Begin txns in both sessions
145137
$result = $s1->query_safe("BEGIN");
146-
isnt($result, '', "session 1: begin");
147138

148139
$result = $s2->query_safe("BEGIN");
149-
isnt($result, '', "session 2: begin");
150140

151141
$result = $s2->query_safe($count_query);
152142
is($result, $num_rows, "session 2: validate row count");
@@ -157,7 +147,6 @@
157147

158148
# Session 2 immediately commits, releasing the AccessShareLock on the table
159149
$result = $s2->query_safe("COMMIT");
160-
isnt($result, '', "session 2: commit");
161150

162151
# The result from the previous query_until() is returned with the next query
163152
# so perform a dummy query on s1 to discard the result
@@ -179,7 +168,6 @@
179168
is($result, $expected, "verify AccessExclusiveLock was taken");
180169

181170
$result = $s1->query_safe("ROLLBACK");
182-
isnt($result, '', "session 1: rollback");
183171

184172
$s1->quit();
185173
$s2->quit();

0 commit comments

Comments
 (0)