#!/bin/bash test_promotion () { export codename="$1" export use_port="$2" export directory="data-$codename" finish_trigger="$work_dir/${directory}.finish" touch "$finish_trigger" response="$( tail_n_grep_with_timeout 120 "database system is ready to accept connections" "tail -n 50 -f $directory/log/pg.log" )" if ! ( echo "$response" | grep -q "database system is ready to accept connections" ) then echo "Promotion didn't work for $codename." >&2 exit 1 fi verification="$( psql -F, -qAtX -p $use_port -c ' select min(count), count(distinct count) from ( select r, count(*) from ( select distinct t0.when_tsz as r from t0 union all select distinct t1.when_tsz as r from t1 union all select distinct t2.when_tsz as r from t2 union all select distinct t3.when_tsz as r from t3 union all select distinct t4.when_tsz as r from t4 union all select distinct t5.when_tsz as r from t5 union all select distinct t6.when_tsz as r from t6 union all select distinct t7.when_tsz as r from t7 union all select distinct t8.when_tsz as r from t8 union all select distinct t9.when_tsz as r from t9 ) x group by r) y;' )" if [[ "$verification" != "10,1" ]] then echo "Something is wrong with promoted $codename." >&2 exit 1 fi }