Allow isolation test steps to be declared inline.
Allow isolation test steps to be declared inline.
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 " { }". 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
Re: Allow isolation test steps to be declared inline.
От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:
> On 21 Nov 2026, at 19:12, Dean Rasheed 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.
Re: Allow isolation test steps to be declared inline.
От:
Dean Rasheed <dean.a.rasheed@gmail.com>
Дата:
On Sat, 21 Nov 2026 at 15:26, Andrey Borodin 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