On Mon, Dec 11, 2023 at 3:14 PM Michael Paquier <[email protected]> wrote:
>
> On Mon, Dec 11, 2023 at 11:09:45AM +0530, Dilip Kumar wrote:
> > I haven't specifically done a review or testing of this patch, but I
> > have used this for testing the CLOG group update code with my
> > SLRU-specific changes and I found it quite helpful to test some of the
> > concurrent areas where you need to stop processing somewhere in the
> > middle of the code and testing that area without this kind of
> > injection point framework is really difficult or may not be even
> > possible. We wanted to test the case of clog group update where we
> > can get multiple processes added to a single group and get the xid
> > status updated by the group leader, you can refer to my test in that
> > thread[1] (the last patch test_group_commit.patch is using this
> > framework for testing).
>
> Could you be more specific? test_group_commit.patch includes this
> line but there is nothing specific about this injection point getting
> used in a test or a callback assigned to it:
> ./test_group_commit.patch:+ INJECTION_POINT("ClogGroupCommit");
Oops, I only included the code changes where I am adding injection
points and some comments to verify that, but missed the actual test
file. Attaching it here.
Note: I think the latest patches are conflicting with the head, can you rebase?
--
Regards,
Dilip Kumar
EnterpriseDB: http://www.enterprisedb.com
# Test clog group update
use strict;
use warnings;
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;
my $node = PostgreSQL::Test::Cluster->new('node');
$node->init(allows_streaming => 'logical');
$node->start;
$node->safe_psql('postgres', 'CREATE EXTENSION test_injection_points;');
$node->safe_psql('postgres', 'CREATE TABLE test(a int);');
# Consume multiple xids so that next xids get generated in new banks
$node->safe_psql(
'postgres', q{
do $$
begin
for i in 1..128001 loop
-- use an exception block so that each iteration eats an XID
begin
insert into test values (i);
exception
when division_by_zero then null;
end;
end loop;
end$$;
});
#attach to the injection point
$node->safe_psql('postgres',
"SELECT test_injection_points_attach('ClogGroupCommit', 'wait');");
# First session will get the slru lock and will wait on injection point
my $session1 = $node->background_psql('postgres');
$session1->query_until(
qr/start/, q(
\echo start
INSERT INTO test VALUES(1);
));
#create another 4 session which will not get the lock as first session is holding that lock
#so these all will go for group update
my $session2 = $node->background_psql('postgres');
$session2->query_until(
qr/start/, q(
\echo start
INSERT INTO test VALUES(2);
));
my $session3 = $node->background_psql('postgres');
$session3->query_until(
qr/start/, q(
\echo start
INSERT INTO test VALUES(3);
));
my $session4 = $node->background_psql('postgres');
$session4->query_until(
qr/start/, q(
\echo start
INSERT INTO test VALUES(4);
));
my $session5 = $node->background_psql('postgres');
$session5->query_until(
qr/start/, q(
\echo start
INSERT INTO test VALUES(5);
));
# Now wake up the first session and let next 4 session perform the group update
$node->safe_psql('postgres',
"SELECT test_injection_points_wake();");
$node->safe_psql('postgres',
"SELECT test_injection_points_detach('ClogGroupCommit');");
done_testing();