#!/usr/bin/bash

PORT=$1
DURATION=$2

# recreate directory with sequence states
rm -Rf states
mkdir states

start_time=`date +%s`
nloops=0
nerrors=0

while /bin/true; do

	psql -p $PORT test -c "ALTER SUBSCRIPTION s REFRESH PUBLICATION"

	nloops=$((nloops+1))

	echo "loop $nloops"

	t=`date +%s`
	d=$((t-start_time))

	if [ $d -gt $DURATION ]; then
		break
	fi

	# psql -p $SUB_PORT test -c "SELECT pg_sleep(random())"

done

echo 'loops' $nloops 'errors' $nerrors
