I think it'd be nice to have a set of macros that can create wait points in the C code that isolation tests can control, in a special build. Perhaps there could be shm hash table of named wait points in shared memory; if DEBUG_WAIT_POINT("foo") finds that "foo" is not present, it continues, but if it finds an entry it waits for it to go away. Then isolation tests could add/remove names and signal a condition variable to release waiters.
I contemplated that while working on SKIP LOCKED, which had a bunch of weird edge cases that I tested by inserting throw-away wait-point code like this:
Yes, I agree it would be nice to have a framework like this.
Greenplum actually has a fault injection framework that, I believe, works similarly to what you are describing -- i.e. sets a variable in shared memory. There is an extension, gp_inject_fault, which allows you to set the faults. Andreas Scherbaum wrote a blog post about how to use it [1].
The Greenplum implementation is not documented particularly well in the code, but, it is something that folks working on Greenplum have talked about modifying and proposing to Postgres.