Unit tests for SLRU

Aleksander Alekseev <aleksander@timescale.com>

From: Aleksander Alekseev <aleksander@timescale.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Date: 2022-03-31T14:30:41Z
Lists: pgsql-hackers

Attachments

Hi hackers,

I learned from Peter [1] that SLRU test coverage leaves much to be
desired and makes it difficult to refactor it. Here is a draft of a
patch that tries to address it.

I used src/test/modules/test_* modules as an example. While on it, I
moved the Asserts() outside of SimpleLruInit(). It didn't seem to be a
right place to check the IsUnderPostmaster value, and complicated the
test implementation. I also renamed SlruSyncFileTag() to
SlruSyncSegment() and changed its signature. I think it makes the
interface easier to reason about.

I noticed that SLRU uses int's for slotno, while FileTag->slotno is
uint32. Can't this cause us any grief? Finally, I believe
SimpleLruWritePage() name is confusing, because in fact it works with
a slot, not a page. But I didn't change the name in my patch, yet.

If time permits, please take a quick look at the patch and let me know
if I'm moving the right direction. There will be more tests in the
final version, but I would appreciate an early feedback.

[1]: https://postgr.es/m/220fab30-dff0-b055-f803-4338219f1021%40enterprisedb.com

-- 
Best regards,
Aleksander Alekseev

Commits

  1. Add test module for SLRUs

  2. Fix comment of SimpleLruInit() in slru.c