Adds a connection string (constr) to run tests on that connection

connection-string-tests-9.2-include
Halil Ozan Akgul 2020-02-19 16:02:42 +03:00
parent 7188574c62
commit b7612aa208
2 changed files with 160 additions and 68 deletions

View File

@ -116,7 +116,7 @@ check-empty: all
-- $(MULTI_REGRESS_OPTS) $(EXTRA_TESTS) -- $(MULTI_REGRESS_OPTS) $(EXTRA_TESTS)
check-multi: all check-multi: all
$(pg_regress_multi_check) --load-extension=citus \ $(pg_regress_multi_check) --constr="$(constr)" --load-extension=citus \
-- $(MULTI_REGRESS_OPTS) --schedule=$(citus_abs_srcdir)/multi_schedule $(EXTRA_TESTS) -- $(MULTI_REGRESS_OPTS) --schedule=$(citus_abs_srcdir)/multi_schedule $(EXTRA_TESTS)
check-multi-non-adaptive: all check-multi-non-adaptive: all

View File

@ -80,6 +80,7 @@ my $pgCtlTimeout = undef;
my $connectionTimeout = 5000; my $connectionTimeout = 5000;
my $useMitmproxy = 0; my $useMitmproxy = 0;
my $mitmFifoPath = catfile($TMP_CHECKDIR, "mitmproxy.fifo"); my $mitmFifoPath = catfile($TMP_CHECKDIR, "mitmproxy.fifo");
my $constr = "";
my $serversAreShutdown = "TRUE"; my $serversAreShutdown = "TRUE";
my $usingWindows = 0; my $usingWindows = 0;
@ -108,6 +109,7 @@ GetOptions(
'pg_ctl-timeout=s' => \$pgCtlTimeout, 'pg_ctl-timeout=s' => \$pgCtlTimeout,
'connection-timeout=s' => \$connectionTimeout, 'connection-timeout=s' => \$connectionTimeout,
'mitmproxy' => \$useMitmproxy, 'mitmproxy' => \$useMitmproxy,
'constr=s' => \$constr,
'help' => sub { Usage() }); 'help' => sub { Usage() });
# Update environment to include [DY]LD_LIBRARY_PATH/LIBDIR/etc - # Update environment to include [DY]LD_LIBRARY_PATH/LIBDIR/etc -
@ -261,6 +263,10 @@ sub revert_replace_postgres
# partial run, even if we're now not using valgrind. # partial run, even if we're now not using valgrind.
revert_replace_postgres(); revert_replace_postgres();
my $host = "localhost";
my $user = "postgres";
my $dbname = "postgres";
# n.b. previously this was on port 57640, which caused issues because that's in the # n.b. previously this was on port 57640, which caused issues because that's in the
# ephemeral port range, it was sometimes in the TIME_WAIT state which prevented us from # ephemeral port range, it was sometimes in the TIME_WAIT state which prevented us from
# binding to it. 9060 is now used because it will never be used for client connections, # binding to it. 9060 is now used because it will never be used for client connections,
@ -270,12 +276,45 @@ my $mitmPort = 9060;
# Set some default configuration options # Set some default configuration options
my $masterPort = 57636; my $masterPort = 57636;
my $workerCount = 2; my $workerCount = 2;
my @workerPorts = (); my @workerPorts = ();
for (my $workerIndex = 1; $workerIndex <= $workerCount; $workerIndex++) { if ( $constr )
{
my %convals = split /=|\s/, $constr;
if (exists $convals{user})
{
$user = $convals{user};
}
if (exists $convals{host})
{
$host = $convals{host};
}
if (exists $convals{port})
{
$masterPort = $convals{port};
}
if (exists $convals{dbname})
{
$dbname = $convals{dbname};
}
my $worker1port = `psql "$constr" -t -c "SELECT nodeport FROM pg_dist_node ORDER BY nodeid LIMIT 1;"`;
my $worker2port = `psql "$constr" -t -c "SELECT nodeport FROM pg_dist_node ORDER BY nodeid OFFSET 1 LIMIT 1;"`;
$worker1port =~ s/^\s+|\s+$//g;
$worker2port =~ s/^\s+|\s+$//g;
push(@workerPorts, $worker1port);
push(@workerPorts, $worker2port);
}
else
{
for (my $workerIndex = 1; $workerIndex <= $workerCount; $workerIndex++) {
my $workerPort = $masterPort + $workerIndex; my $workerPort = $masterPort + $workerIndex;
push(@workerPorts, $workerPort); push(@workerPorts, $workerPort);
}
} }
my $followerCoordPort = 9070; my $followerCoordPort = 9070;
@ -285,8 +324,6 @@ for (my $workerIndex = 1; $workerIndex <= $workerCount; $workerIndex++) {
push(@followerWorkerPorts, $workerPort); push(@followerWorkerPorts, $workerPort);
} }
my $host = "localhost";
my $user = "postgres";
my @pgOptions = (); my @pgOptions = ();
# Postgres options set for the tests # Postgres options set for the tests
@ -392,7 +429,15 @@ for my $option (@userPgOptions)
} }
# define functions as signature->definition # define functions as signature->definition
%functions = ('fake_fdw_handler()', 'fdw_handler AS \'citus\' LANGUAGE C STRICT;'); %functions = ();
if (!$constr)
{
%functions = ('fake_fdw_handler()', 'fdw_handler AS \'citus\' LANGUAGE C STRICT;');
}
else
{
%functions = ('fake_fdw_handler()', 'fdw_handler AS \'\'citus\'\' LANGUAGE C STRICT;');
}
#define fdws as name->handler name #define fdws as name->handler name
%fdws = ('fake_fdw', 'fake_fdw_handler'); %fdws = ('fake_fdw', 'fake_fdw_handler');
@ -488,49 +533,52 @@ else
} }
close $fh; close $fh;
make_path(catfile($TMP_CHECKDIR, $MASTERDIR, 'log')) or die "Could not create $MASTERDIR directory";
for my $port (@workerPorts) if (!$constr)
{ {
make_path(catfile($TMP_CHECKDIR, $MASTERDIR, 'log')) or die "Could not create $MASTERDIR directory";
for my $port (@workerPorts)
{
make_path(catfile($TMP_CHECKDIR, "worker.$port", "log")) make_path(catfile($TMP_CHECKDIR, "worker.$port", "log"))
or die "Could not create worker directory"; or die "Could not create worker directory";
} }
if ($followercluster) if ($followercluster)
{ {
make_path(catfile($TMP_CHECKDIR, $MASTER_FOLLOWERDIR, 'log')) or die "Could not create $MASTER_FOLLOWERDIR directory"; make_path(catfile($TMP_CHECKDIR, $MASTER_FOLLOWERDIR, 'log')) or die "Could not create $MASTER_FOLLOWERDIR directory";
for my $port (@followerWorkerPorts) for my $port (@followerWorkerPorts)
{ {
make_path(catfile($TMP_CHECKDIR, "follower.$port", "log")) make_path(catfile($TMP_CHECKDIR, "follower.$port", "log"))
or die "Could not create worker directory"; or die "Could not create worker directory";
} }
} }
# Create new data directories, copy workers for speed # Create new data directories, copy workers for speed
system(catfile("$bindir", "initdb"), ("--nosync", "-U", $user, "--encoding", "UTF8", catfile($TMP_CHECKDIR, $MASTERDIR, "data"))) == 0 system(catfile("$bindir", "initdb"), ("--nosync", "-U", $user, "--encoding", "UTF8", catfile($TMP_CHECKDIR, $MASTERDIR, "data"))) == 0
or die "Could not create $MASTERDIR data directory"; or die "Could not create $MASTERDIR data directory";
if ($usingWindows) if ($usingWindows)
{ {
for my $port (@workerPorts) for my $port (@workerPorts)
{ {
system(catfile("$bindir", "initdb"), ("--nosync", "-U", $user, "--encoding", "UTF8", catfile($TMP_CHECKDIR, "worker.$port", "data"))) == 0 system(catfile("$bindir", "initdb"), ("--nosync", "-U", $user, "--encoding", "UTF8", catfile($TMP_CHECKDIR, "worker.$port", "data"))) == 0
or die "Could not create worker data directory"; or die "Could not create worker data directory";
} }
} }
else else
{ {
for my $port (@workerPorts) for my $port (@workerPorts)
{ {
system("cp", ("-a", catfile($TMP_CHECKDIR, $MASTERDIR, "data"), catfile($TMP_CHECKDIR, "worker.$port", "data"))) == 0 system("cp", ("-a", catfile($TMP_CHECKDIR, $MASTERDIR, "data"), catfile($TMP_CHECKDIR, "worker.$port", "data"))) == 0
or die "Could not create worker data directory"; or die "Could not create worker data directory";
} }
}
} }
# Routine to shutdown servers at failure/exit # Routine to shutdown servers at failure/exit
sub ShutdownServers() sub ShutdownServers()
{ {
if ($serversAreShutdown eq "FALSE") if (!$constr && $serversAreShutdown eq "FALSE")
{ {
system(catfile("$bindir", "pg_ctl"), system(catfile("$bindir", "pg_ctl"),
('stop', '-w', '-D', catfile($TMP_CHECKDIR, $MASTERDIR, 'data'))) == 0 ('stop', '-w', '-D', catfile($TMP_CHECKDIR, $MASTERDIR, 'data'))) == 0
@ -657,17 +705,19 @@ if ($followercluster)
} }
# Start servers # Start servers
if(system(catfile("$bindir", "pg_ctl"), if (!$constr)
{
if(system(catfile("$bindir", "pg_ctl"),
('start', '-w', ('start', '-w',
'-o', join(" ", @pgOptions)." -c port=$masterPort $synchronousReplication", '-o', join(" ", @pgOptions)." -c port=$masterPort $synchronousReplication",
'-D', catfile($TMP_CHECKDIR, $MASTERDIR, 'data'), '-l', catfile($TMP_CHECKDIR, $MASTERDIR, 'log', 'postmaster.log'))) != 0) '-D', catfile($TMP_CHECKDIR, $MASTERDIR, 'data'), '-l', catfile($TMP_CHECKDIR, $MASTERDIR, 'log', 'postmaster.log'))) != 0)
{ {
system("tail", ("-n20", catfile($TMP_CHECKDIR, $MASTERDIR, "log", "postmaster.log"))); system("tail", ("-n20", catfile($TMP_CHECKDIR, $MASTERDIR, "log", "postmaster.log")));
die "Could not start master server"; die "Could not start master server";
} }
for my $port (@workerPorts) for my $port (@workerPorts)
{ {
if(system(catfile("$bindir", "pg_ctl"), if(system(catfile("$bindir", "pg_ctl"),
('start', '-w', ('start', '-w',
'-o', join(" ", @pgOptions)." -c port=$port $synchronousReplication", '-o', join(" ", @pgOptions)." -c port=$port $synchronousReplication",
@ -677,6 +727,7 @@ for my $port (@workerPorts)
system("tail", ("-n20", catfile($TMP_CHECKDIR, "worker.$port", "log", "postmaster.log"))); system("tail", ("-n20", catfile($TMP_CHECKDIR, "worker.$port", "log", "postmaster.log")));
die "Could not start worker server"; die "Could not start worker server";
} }
}
} }
# Setup the follower nodes # Setup the follower nodes
@ -724,8 +775,10 @@ if ($followercluster)
# Create database, extensions, types, functions and fdws on the workers, # Create database, extensions, types, functions and fdws on the workers,
# pg_regress won't know to create them for us. # pg_regress won't know to create them for us.
### ###
for my $port (@workerPorts) if (!$constr)
{ {
for my $port (@workerPorts)
{
system(catfile($bindir, "psql"), system(catfile($bindir, "psql"),
('-X', '-h', $host, '-p', $port, '-U', $user, "-d", "postgres", ('-X', '-h', $host, '-p', $port, '-U', $user, "-d", "postgres",
'-c', "CREATE DATABASE regression;")) == 0 '-c', "CREATE DATABASE regression;")) == 0
@ -762,6 +815,40 @@ for my $port (@workerPorts)
'-c', "CREATE SERVER $fdwServer FOREIGN DATA WRAPPER $fdwServers{$fdwServer};")) == 0 '-c', "CREATE SERVER $fdwServer FOREIGN DATA WRAPPER $fdwServers{$fdwServer};")) == 0
or die "Could not create server $fdwServer on worker"; or die "Could not create server $fdwServer on worker";
} }
}
}
else
{
for my $extension (@extensions)
{
system(catfile($bindir, "psql"),
('-X', '-h', $host, '-p', $masterPort, '-U', $user, "-d", $dbname,
'-c', "SELECT run_command_on_workers('CREATE EXTENSION IF NOT EXISTS $extension;');")) == 0
or die "Could not create extension on worker";
}
foreach my $function (keys %functions)
{
system(catfile($bindir, "psql"),
('-X', '-h', $host, '-p', $masterPort, '-U', $user, "-d", $dbname,
'-c', "SELECT run_command_on_workers('CREATE FUNCTION $function RETURNS $functions{$function};');")) == 0
or die "Could not create FUNCTION $function on worker";
}
foreach my $fdw (keys %fdws)
{
system(catfile($bindir, "psql"),
('-X', '-h', $host, '-p', $masterPort, '-U', $user, "-d", $dbname,
'-c', "SELECT run_command_on_workers('CREATE FOREIGN DATA WRAPPER $fdw HANDLER $fdws{$fdw};');")) == 0
or die "Could not create foreign data wrapper $fdw on worker";
}
foreach my $fdwServer (keys %fdwServers)
{
system(catfile($bindir, "psql"),
('-X', '-h', $host, '-p', $masterPort, '-U', $user, "-d", $dbname,
'-c', "SELECT run_command_on_workers('CREATE SERVER $fdwServer FOREIGN DATA WRAPPER $fdwServers{$fdwServer};');")) == 0
or die "Could not create server $fdwServer on worker";
}
} }
# Prepare pg_regress arguments # Prepare pg_regress arguments
@ -814,6 +901,11 @@ elsif ($isolationtester)
} }
else else
{ {
if ($constr)
{
push(@arguments, "--dbname=$dbname");
push(@arguments, "--use-existing");
}
$exitcode = system("$plainRegress", @arguments); $exitcode = system("$plainRegress", @arguments);
} }