Re: [PATCH] Add tests for Bitmapset

From: Greg Burd <greg(at)burd(dot)me>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>
Subject: Re: [PATCH] Add tests for Bitmapset
Date: 2025-09-15 19:56:30
Message-ID: 1CA731DE-B1BD-45C2-95B5-7E83FFE0E35C@greg.burd.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On Sep 15 2025, at 3:03 pm, Greg Burd <greg(at)burd(dot)me> wrote:

> On Sep 15 2025, at 2:54 pm, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>
>> On Mon, Sep 15, 2025 at 2:00 PM Greg Burd <greg(at)burd(dot)me> wrote:
>>> For reference radixtree has:
>>>
>>> coverage: HEAD
>>> lines......: 98.3
>>> functions..: 97.2
>>> branches...: 89.4
>>
>> + /* Test negative member in bms_make_singleton */
>> + error_caught = false;
>> + PG_TRY();
>> + {
>> + bms_make_singleton(-1);
>> + }
>> + PG_CATCH();
>> + {
>> + error_caught = true;
>> + FlushErrorState();
>> + }
>> + PG_END_TRY();
>> + EXPECT_TRUE(error_caught);
>>
>> This is an anti-pattern for PostgreSQL code. You can't just flush an
>> error without aborting a transaction or subtransaction to recover.
>> Even if it could be shown that this were harmless here, I think it's a
>> terrible idea to have code like this in the tree, as it encourages
>> people to do exactly the wrong thing.
>
> Fair enough, I'll rework it.
>
>> But backing up a step, this also doesn't really seem like the right
>> way to test the error conditions. It deliberately throws away the
>> error message. All this verifies is that you caught an error. If you
>> let the error escape to the client you could have the expected output
>> test that you got the expected message.
>>
>> I think it would be a better idea to structure this as a set of
>> SQL-callable functions and move a bunch of the logic into SQL.
>
> I'll give that approach a try, thanks for the suggestion.
>
> -greg

Robert,

Reworked as indicated, thanks for pointing out the anti-pattern I'd
missed.

best.

-greg

>> --
>> Robert Haas
>> EDB: http://www.enterprisedb.com

Attachment Content-Type Size
v3-0001-Add-a-module-that-tests-Bitmapset.patch application/octet-stream 28.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-09-15 20:01:47 Re: Identifying function-lookup failures due to argument name mismatches
Previous Message Tom Lane 2025-09-15 19:43:46 Re: plan shape work