TAP test utility module 'PG_LSN.pm'

Started by Craig Ringerabout 5 years ago5 messages
#1Craig Ringer
craig.ringer@enterprisedb.com
1 attachment(s)

Hi all

I'd like to share the attached PG_LSN.pm module that I use when
writing TAP tests. I suggest that it be considered for inclusion in
core.

It defines a Perl datatype PG_LSN with operator support, so you can
write things like

cmp_ok($got_lsn, "<", $expected_lsn, "testname")

in TAP tests and get sensible results without any concern for LSN
representation details, locale, etc. You can subtract LSNs to get a
byte difference too.

It's small but I've found it handy.

Attachments:

PG_LSN.pmapplication/x-perl; name=PG_LSN.pmDownload
#2Michael Paquier
michael@paquier.xyz
In reply to: Craig Ringer (#1)
Re: TAP test utility module 'PG_LSN.pm'

On Tue, Dec 01, 2020 at 12:03:41PM +0800, Craig Ringer wrote:

I'd like to share the attached PG_LSN.pm module that I use when
writing TAP tests. I suggest that it be considered for inclusion in
core.

It defines a Perl datatype PG_LSN with operator support, so you can
write things like

cmp_ok($got_lsn, "<", $expected_lsn, "testname")

in TAP tests and get sensible results without any concern for LSN
representation details, locale, etc. You can subtract LSNs to get a
byte difference too.

In my experience, any TAP tests making use of LSN operations can just
let the backend do the maths, so I am not much a fan of duplicating
that stuff in a perl module. Wouldn't it be better to add an
equivalent of your add() function in the backend then? That could
also get tested in the main regression test suite.
--
Michael

#3Craig Ringer
craig.ringer@enterprisedb.com
In reply to: Michael Paquier (#2)
Re: TAP test utility module 'PG_LSN.pm'

On Tue, 1 Dec 2020 at 13:58, Michael Paquier <michael@paquier.xyz> wrote:

On Tue, Dec 01, 2020 at 12:03:41PM +0800, Craig Ringer wrote:

I'd like to share the attached PG_LSN.pm module that I use when
writing TAP tests. I suggest that it be considered for inclusion in
core.

It defines a Perl datatype PG_LSN with operator support, so you can
write things like

cmp_ok($got_lsn, "<", $expected_lsn, "testname")

in TAP tests and get sensible results without any concern for LSN
representation details, locale, etc. You can subtract LSNs to get a
byte difference too.

In my experience, any TAP tests making use of LSN operations can just
let the backend do the maths, so I am not much a fan of duplicating
that stuff in a perl module. Wouldn't it be better to add an
equivalent of your add() function in the backend then? That could
also get tested in the main regression test suite.

I find it convenient not to have as much log spam. Also, IIRC I needed
it at some points where the target backend(s) were down while I was
testing something related to a backend that was still in recovery and
not yet available for querying.

I don't really mind though, I'm just sharing what I have found useful.

#4Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: Michael Paquier (#2)
Re: TAP test utility module 'PG_LSN.pm'

On 2020/12/01 14:58, Michael Paquier wrote:

On Tue, Dec 01, 2020 at 12:03:41PM +0800, Craig Ringer wrote:

I'd like to share the attached PG_LSN.pm module that I use when
writing TAP tests. I suggest that it be considered for inclusion in
core.

It defines a Perl datatype PG_LSN with operator support, so you can
write things like

cmp_ok($got_lsn, "<", $expected_lsn, "testname")

in TAP tests and get sensible results without any concern for LSN
representation details, locale, etc. You can subtract LSNs to get a
byte difference too.

In my experience, any TAP tests making use of LSN operations can just
let the backend do the maths, so I am not much a fan of duplicating
that stuff in a perl module.

Agreed.

Wouldn't it be better to add an
equivalent of your add() function in the backend then?

You mean the same function as the commit 9bae7e4cde provided?

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

#5Michael Paquier
michael@paquier.xyz
In reply to: Fujii Masao (#4)
Re: TAP test utility module 'PG_LSN.pm'

On Tue, Dec 01, 2020 at 03:14:06PM +0900, Fujii Masao wrote:

You mean the same function as the commit 9bae7e4cde provided?

Completely forgot about this one, thanks.

/me hides
--
Michael