Skip to content

Commit

Permalink
Merge pull request #7 from postgrespro/PGPRO-4965
Browse files Browse the repository at this point in the history
Code cleanup and tests stability
  • Loading branch information
arssher authored Apr 16, 2021
2 parents d5d1254 + 7cc27c7 commit 029970c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cluster.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sub mm_get_free_port
if ($found == 1)
{
foreach my $addr (qw(127.0.0.1),
$PostgresNode::use_tcp ? qw(127.0.0.2 127.0.0.3 0.0.0.0) : ())
$PostgresNode::use_tcp && ($^O eq "linux" || $windows_os) ? qw(127.0.0.2 127.0.0.3 0.0.0.0) : ())
{
if (!PostgresNode::can_bind($addr, $port))
{
Expand Down
6 changes: 0 additions & 6 deletions src/pglogical_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,6 @@ pglogical_receiver_main(Datum main_arg)
/* Create new slot if needed */
query = createPQExpBuffer();

/* TODO: remove this once we rebase onto fresh version of EE which
* doesn't use MessageContext inside planner guts (PGPRO-3253)*/
MessageContext = AllocSetContextCreate(TopMemoryContext,
"MessageContext",
ALLOCSET_DEFAULT_SIZES);

/*
* Make sure config is up to date as we are going to check out
* backup_node_id; if it has been cleared we must be aware of that.
Expand Down
34 changes: 22 additions & 12 deletions t/008_bugfixes.pl
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use Carp;
use POSIX;
use strict;
use Test::More;
use TestLib;
use Time::HiRes qw(usleep);
use warnings;
use Carp;

use PostgresNode;
use Cluster;
use TestLib;
use Test::More;

use Test::More tests => Cluster::is_ee() ? 6 : 5;

my $cluster = new Cluster(3);
$cluster->init();
Expand Down Expand Up @@ -42,7 +47,7 @@
$hash2 = $cluster->safe_psql(2, $hash_query);
note("$hash0, $hash1, $hash2");
is( (($hash0 eq $hash1) and ($hash1 eq $hash2)) , 1,
"Check that hash is the same after query");
"Check that hash is the same after query");
}

$cluster->safe_psql(0, q{
Expand Down Expand Up @@ -72,7 +77,7 @@
$hash2 = $cluster->safe_psql(2, $hash_query);
note("$hash0, $hash1, $hash2");
is( (($hash0 eq $hash1) and ($hash1 eq $hash2)) , 1,
"Check that hash is the same after query");
"Check that hash is the same after query");

# ##############################################################################
#
Expand All @@ -93,30 +98,35 @@

# Simulate payload
$cluster->pgbench(0, ('-i', '-n', -s => '1') );
my $pgb1 = $cluster->pgbench_async(0, ('-n', -T => '15', -j=>'5', -c => '5') );
sleep(5);
note( strftime('%Y-%m-%d %H:%M:%S', localtime) . ": starting async pgbench" );
my $pgb1 = $cluster->pgbench_async(0, ('-n', -T => '25', -j => '1', -c => '5') );

my $pid0;
my $attempts = 0;

note( strftime('%Y-%m-%d %H:%M:%S', localtime) . ": starting polling of backend pid" );
while (1)
{
$pid0 = $cluster->safe_psql(0, "SELECT pid FROM pg_stat_activity
WHERE backend_type LIKE 'client backend'
AND query LIKE 'UPDATE%' LIMIT 1;");

# bf says we might be really unlucky to find no backend doing update
if ($pid0 ne "")
# It does not make much sense to try longer than pgbench run lasts,
# since we need an active backend to kill. So let it be 25 seconds
# both for pgbench_async() and this pg_stat_activity polling.
if ( ($pid0 ne "") || $attempts >= 25*10 )
{
last;
}

# Wait 0.1 second before retrying.
usleep(100_000);
$attempts++;
if ($attempts >= 180*10)
{
croak 'failed to fetch backend pid';
}
}
note( strftime('%Y-%m-%d %H:%M:%S', localtime) . ": finished polling of backend pid" );
is( ($pid0 ne ""), 1,
"found an active backend doing UPDATE" );

# Simulate hard crash
note("Simulate hard crash of a backend by SIGKILL to $pid0");
Expand Down

0 comments on commit 029970c

Please sign in to comment.