On Wed, Sep 22, 2021 at 6:59 PM Mark Dilger <mark.dil...@enterprisedb.com> wrote: > > > > > On Sep 22, 2021, at 6:14 AM, Amul Sul <sula...@gmail.com> wrote: > > > >> Attached patch v34-0010 adds a test of cursors opened FOR UPDATE > >> interacting with a system that is set read-only by a different session. > >> The expected output is worth reviewing to see how this plays out. I don't > >> see anything in there which is obviously wrong, but some of it is a bit > >> clunky. For example, by the time the client sees an error "FATAL: WAL is > >> now prohibited", the system may already have switched back to read-write. > >> Also, it is a bit strange to get one of these errors on an attempted > >> ROLLBACK. Once again, not wrong as such, but clunky. > >> > > > > Can't we do the same in the TAP test? If the intention is only to test > > session termination when the system changes to WAL are prohibited then > > that I have added in the latest version, but that test does not > > reinitiate the same connection again, I think that is not possible > > there too. > > Perhaps you can point me to a TAP test that does this in a concise fashion. > When I tried writing a TAP test for this, it was much longer than the > equivalent isolation test spec. >
Yes, that is a bit longer, here is the snip from v35-0010 patch: +my $psql_timeout = IPC::Run::timer(60); +my ($mysession_stdin, $mysession_stdout, $mysession_stderr) = ('', '', ''); +my $mysession = IPC::Run::start( + [ + 'psql', '-X', '-qAt', '-v', 'ON_ERROR_STOP=1', '-f', '-', '-d', + $node_primary->connstr('postgres') + ], + '<', + \$mysession_stdin, + '>', + \$mysession_stdout, + '2>', + \$mysession_stderr, + $psql_timeout); + +# Write in transaction and get backend pid +$mysession_stdin .= q[ +BEGIN; +INSERT INTO tab VALUES(7); +SELECT $$value-7-inserted-into-tab$$; +]; +$mysession->pump until $mysession_stdout =~ /value-7-inserted-into-tab[\r\n]$/; +like($mysession_stdout, qr/value-7-inserted-into-tab/, + 'started write transaction in a session'); +$mysession_stdout = ''; +$mysession_stderr = ''; + +# Change to WAL prohibited +$node_primary->safe_psql('postgres', 'SELECT pg_prohibit_wal(true)'); +is($node_primary->safe_psql('postgres', $show_wal_prohibited_query), 'on', + 'server is changed to wal prohibited by another session'); + +# Try to commit open write transaction. +$mysession_stdin .= q[ +COMMIT; +]; +$mysession->pump; +like($mysession_stderr, qr/FATAL: WAL is now prohibited/, + 'session with open write transaction is terminated'); Regards, Amul