Skip to content

Strip whitespace when checking query results in TAP tests #8048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/perl/TimescaleNode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,19 @@ sub psql_is
"$testname: psql output check");
}

# remove leading and trailing whitespace
sub strip
{
my ($self, $str) = @_;
$str =~ s/^\s+|\s+$//g;
return $str;
}
Comment on lines +59 to +65
Copy link
Contributor

@mkindahl mkindahl May 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This is so simple that I'm not sure a function is needed, but whatever. Also, indentation makes it look like it is an if, and $self is never used. Maybe just skip the $self and use it as a plain function similar to how they are defined in https://perlmaven.com/trim.


sub safe_psql
{
my ($self, $db, $query) = @_;
my $psql_out = $self->SUPER::safe_psql($db, $query);
return $self->strip($psql_out);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove $self, this would be:

Suggested change
return $self->strip($psql_out);
return strip($psql_out);

}

1;
2 changes: 1 addition & 1 deletion tsl/test/t/001_job_crash_log.pl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ END
my $query_add =
q[select add_job('custom_proc_sleep60', '5 minutes', initial_start => now())];
my $jobid = $node->safe_psql('postgres', "$query_add");
is($jobid, '1000', 'job was added');
is($jobid, 1000, 'job was added');

my $query_pid_exists = <<"END_OF_QUERY";
select count(*) from pg_stat_activity
Expand Down
16 changes: 2 additions & 14 deletions tsl/test/t/004_truncate_or_delete_spin_lock.pl
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@
temperature double precision null);
}
);
is($result, '', 'create table');

# Create hypertable
$result = $node->safe_psql(
'postgres', q{
SELECT FROM create_hypertable('sensor_data','time', chunk_time_interval => INTERVAL '1 month');
SELECT table_name FROM create_hypertable('sensor_data','time', chunk_time_interval => INTERVAL '1 month');
}
);
is($result, '', 'create hypertable');
is($result, 'sensor_data', 'create hypertable');

# Insert data
$result = $node->safe_psql(
Expand All @@ -52,7 +51,6 @@
ORDER BY time;
}
);
is($result, '', 'insert data');

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

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

# Run tests

Expand All @@ -97,10 +93,8 @@

# Begin txns in both sessions
$result = $s1->query_safe("BEGIN");
isnt($result, '', "session 1: begin");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why removing those isnt?? isn't it part of the necessary checks for this tap test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt empty string is not a meaningful test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: statement isn't a query, so we should probably use safe_psql here.


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

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

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

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


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

##########################################################################

Expand All @@ -143,10 +135,8 @@

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

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

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

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

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

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

$s1->quit();
$s2->quit();
Expand Down
Loading