Preface:
The aim of the tests here is to verify 
1. correct inter-process communication about changes in an inheritance hierarchy
relevant to a global index, and
2. correct execution of two concurrent transactions.

Cast:
 "foo" - the parent table (column x)
 "bar" - the child table  (columns x and y)
"foox" - global (unique) index on foo.x
P1, P2 - two client processes (probably two psql processes) that 
          are running concurrently. 
          
Notations:
<WAITS> previous statement waits for a 
        concurrent conflicting transaction to finish
<SUCC>  previous statement completes successfully
<UNIQ_ERR> previous statement causes a uniqueness violation

Also, if a line says "<WAITS> (a)", it means: 
for more details, refer to footnote (a) at the end of this test.
-----------------------------------------------------
Test 1

P1                                          P2
create table foo (x int);
create global unique index 
                foox on foo (x);  
                                      create table bar (y int) 
                                                    inherits (foo);
                                      insert into bar values (1,1);
insert into foo values (1);
<UNIQ_ERR>

-----------------------------------------------------
Test 2

P1                                          P2
create table foo (x int);
begin transaction;
create table bar (y int) 
                inherits (foo);
                                      create global index foox on foo(x);
                                      <WAITS> (a)
insert into bar values (1,1);
commit;
                                      <SUCC>
                                      set enable_seqscan to false;
                                      set enable_bitmapscan to false;
                                      explain select * from foo 
                                          where x > 0 order by x;
                                      select * from foo 
                                          where x > 0 order by x;
                                      <SUCC> (b)
                                      set enable_seqscan to true;
                                      set enable_bitmapscan to true;
                                      
(a) needs to include bar in the global index if the transaction creating
bar commits.
(b) shows that the row in bar has been indexed in the global index.
----------------------------------------------------- 
Test 3

P1                                          P2
create table foo (x int);
begin transaction;
create table bar (y int) 
                inherits (foo);
                                      create global unique index foox on foo(x);
                                      <WAITS> (a)
insert into bar values (1,1);
commit;
                                      <SUCC>
                                      insert into foo values (1);
                                      <UNIQ_ERR> (b)
                                      
(a) same as in previous test
(b) conflicts with value in bar
-----------------------------------------------------
Test 4

P1                                          P2
create table foo (x int);
create global unique index 
              foox on foo(x);   
                                      begin transaction;
                                      create table bar (y int) inherits (foo);
insert into foo values (1);
<WAITS> (a)
                                      insert into bar values (1,1);
                                      commit/rollback;
<UNIQ_ERR/SUCC>

(a) a new child, bar, is being created. Any entries in it might conflict
with the value "1" that is being inserted into foo. So we have to wait till
the transaction creating bar finishes.

-----------------------------------------------------
Test 5
P1                                          P2
create table foo (x int);
create table bar (y int) 
              inherits (foo);
insert into foo values (1);             
insert into bar values (1,1);
begin transaction;
alter table bar no inherit foo;
                                       create global unique index foox on foo(x);
                                       <WAITS> (a)
commit/rollback;
                                       <SUCC>/<UNIQ_ERR> (b)

(a) a child (bar) may be removed; so we have to wait till the transaction
that's removing bar from the inheritance hierarchy finishes.
(b) if P1 does a commit, then index creation in P2 succeeds because the 
duplicate entry in bar is now irrelevant. But if P1 does a rollback, then, 
due to duplicate entries "1" in foo and bar, the index is not created in P2.
-----------------------------------------------------
Test 6

P1                                          P2
create table foo (x int);
create table bar (y int) 
              inherits (foo);
insert into foo values (1);             
insert into bar values (1,1);
begin transaction;
drop table bar;
                                       create global unique index foox on foo(x);
                                       <WAITS> (a)
commit/rollback;
                                       <SUCC>/<UNIQ_ERR>
                                       
(a) This test is similar to the previous one; only difference is that 
bar is DROPped instead of "alter table no inherit".
-----------------------------------------------------
Test 7

P1                                          P2
create table foo (x int);
create table bar (y int) 
              inherits (foo);
create global unique index 
                foox on foo(x);              
insert into foo values (1);             
insert into bar values (2,2);

begin transaction;
alter table bar no inherit foo;
                                       insert into foo values (2);
                                       <WAITS> (a)
commit/rollback;
                                       <SUCC>/<UNIQ_ERR>
                                       
(a) since foox is a unique index, and bar may be removed, an insert into
foo has to wait. This insert will succeed if bar ceases being a child, but 
will fail if bar is too adamant to do so (the value "2" being a duplicate).
-----------------------------------------------------
Test 8

P1                                          P2
create table foo (x int);
create table bar (y int) 
              inherits (foo);
create global index foox on foo(x);              
insert into foo values (1);             
insert into bar values (2,2);

begin transaction;
alter table bar no inherit foo;
                                       insert into foo values (2);
                                       <SUCC> (a)
commit/rollback;
                                       
(a) this case is similar to previous test; but since foox is not
a unique index, the insert into foo need not wait.
-----------------------------------------------------
Test 9

P1                                          P2
create table foo (x int);
create table bar (y int) 
                inherits (foo);
create global unique index 
                foox on foo (x);    
begin transaction;                            
insert into bar values(1,1);
                                    insert into foo values(1);
                                    <WAITS> (a)
commit/rollback;
                                    <UNIQ_ERR>/<SUCC>
                                      
(a) waits to see what happens to the other transaction that's
inserting the duplicate value "1". If the other transaction commits,
then we have a uniqueness violation; otherwise the insert into
foo can proceed.
------------------------------------------------------
Test 10

P1                                          P2
create table foo (x int);
create table bar (y int) 
                inherits (foo);
create global unique index 
                foox on foo (x);                
insert into foo values (1);
insert into bar values (2,2);
begin transaction;
drop table bar;
                                    insert into foo values (2);
                                    <WAITS> (a)
commit/rollback;
                                    <SUCC>/<UNIQ_ERR>
                                                                     
(a) waits to see what happens to the other transaction that's
attempting to drop bar. If bar is dropped, this statement can proceed;
otherwise we have a uniqueness violation.
------------------------------------------------------
