Allow isolation test steps to be declared inline.

Started by Dean Rasheed1 day ago3 messageshackers
Jump to latest
#1Dean Rasheed
dean.a.rasheed@gmail.com

One thing I find annoying when adding new isolation tests is finding
an appropriate place for the new tests, and figuring out whether any
currently defined steps can be reused. If new steps are needed, the
result often seems to be a confusing mess of cryptically named steps,
resulting in something that's not very readable, and only seems to get
worse as more tests are added.

The attached patch allows permutation steps to be written inline,
using the syntax "<session name> { <SQL> }". Thus, for example,
instead of writing this:

permutation "delete1" "insert1" "merge2" "c1" "select2" "c2"

where all the steps are defined elsewhere, the test can be written in
a fully self-contained form like this:

permutation
s1 { DELETE FROM target WHERE key = 1; }
s1 { INSERT INTO target VALUES (1, 'insert1'); }
s2 {
MERGE INTO target t
USING (SELECT 1 as key, 'merge2' as val) s ON s.key = t.key
WHEN NOT MATCHED THEN INSERT VALUES (s.key, s.val)
WHEN MATCHED THEN UPDATE set val = t.val || ' updated by merge2';
}
s1 { COMMIT; }
s2 { SELECT * FROM target; }
s2 { COMMIT; }

That won't be appropriate for all isolation tests (particularly when
there are a large number of permutations sharing the same steps), but
I do think it would be useful a lot of the time when adding new tests.

I'm not proposing to rewrite any existing tests. 0002 (not intended
for commit) does that for a couple of spec files, just to check that
the feature works.

IMO, the inline form is much easier to read, and it makes it easier to
add new tests to existing spec files. It also makes it easier to share
proposed new tests in email threads.

Thoughts?

Regards,
Dean

Attachments:

t259620_1
v1-0001-POC-Allow-isolation-test-steps-to-be-declared-inl.patchtext/x-patch; charset=US-ASCII; name=v1-0001-POC-Allow-isolation-test-steps-to-be-declared-inl.patchDownload+155-21
v1-0002-Test-inline-isolation-test-steps.patchtext/x-patch; charset=US-ASCII; name=v1-0002-Test-inline-isolation-test-steps.patchDownload+165-1
#2Andrey Borodin
amborodin@acm.org
In reply to: Dean Rasheed (#1)
Re: Allow isolation test steps to be declared inline.

On 21 Nov 2026, at 19:12, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:

Thoughts?

Hi Dean,

I like this idea. If a new permutation needs SQL already used by an
inline step, it would be useful to name that step where it first
appears, without moving it back into the session declaration.

Could inline steps optionally have names for reuse in later
permutations? I see that mixing inline and existing named steps is
already supported.

Thank you!

Best regards, Andrey Borodin.

#3Dean Rasheed
dean.a.rasheed@gmail.com
In reply to: Andrey Borodin (#2)
Re: Allow isolation test steps to be declared inline.

On Sat, 21 Nov 2026 at 15:26, Andrey Borodin <x4mmm@yandex-team.ru> wrote:

I like this idea.

Thanks for looking!

If a new permutation needs SQL already used by an
inline step, it would be useful to name that step where it first
appears, without moving it back into the session declaration.

Could inline steps optionally have names for reuse in later
permutations? I see that mixing inline and existing named steps is
already supported.

Hmm, I did think about allowing inline steps to optionally have names,
but for a different reason -- when a step has a parenthesised marker
referring to another inline step to use as a blocking condition, it
would be better if that other step could be given a name, rather than
relying on the generated name, which can change if more steps are
added in between. In the end, I didn't bother because I wanted to keep
the patch simple, and I don't think markers / blocking conditions are
widely used.

However, if inline steps are allowed to have names, it seems more
natural that they be scoped to the containing permutation. If they're
available globally to other permutations, then they're not much
different from named steps defined in session blocks. Perhaps a new
syntax could be invented to allow additional steps to be added to
existing sessions closer to the permutations that need them.

For now though, I'd rather not over-complicate this.

Regards,
Dean