Improve retry logic in 01675_distributed_bytes_to_delay_insert_long

https://clickhouse-test-reports.s3.yandex.net/23517/414d8d0634ea5e3f05d30f53df8531da54a7ff50/functional_stateless_tests_(ubsan).html#fail1
This commit is contained in:
Azat Khuzhin 2021-04-24 15:17:38 +03:00
parent 414d8d0634
commit 313b576aec

View File

@ -51,8 +51,8 @@ function test_max_delay_to_insert_will_throw()
#
function test_max_delay_to_insert_will_succeed_once()
{
local flush_delay=$1 && shift
local max_delay_to_insert=$1 && shift
local max_delay_to_insert=4
local flush_delay=2
drop_tables
@ -64,50 +64,51 @@ function test_max_delay_to_insert_will_succeed_once()
function flush_distributed_worker()
{
sleep "$flush_delay"
sleep $flush_delay
${CLICKHOUSE_CLIENT} -q "system flush distributed dist_01675"
}
flush_distributed_worker &
local start_seconds=$SECONDS
# ignore stderr, since it may produce exception if flushing thread will be too slow
# (this is possible on CI)
${CLICKHOUSE_CLIENT} --testmode -nq "
-- first batch is always OK, since there is no pending bytes yet
insert into dist_01675 select * from numbers(1) settings prefer_localhost_replica=0;
-- second will succeed, due to SYSTEM FLUSH DISTRIBUTED in background.
insert into dist_01675 select * from numbers(1) settings prefer_localhost_replica=0;
"
" >& /dev/null
local end_seconds=$SECONDS
wait
echo $((end_seconds-start_seconds))
local diff=$(( end_seconds-start_seconds ))
if (( diff<(flush_delay-1) )); then
# this is fatal error, that should not be retriable
echo "max_delay_to_insert was not wait flush_delay ($diff)"
exit 1
fi
# retry the test until the diff will be satisfied
# (since we cannot assume that there will be no other lags)
if (( diff>=(max_delay_to_insert-1) )); then
return 1
fi
return 0
}
function test_max_delay_to_insert_will_succeed()
{
echo "max_delay_to_insert will succeed"
local max_delay_to_insert=4
local flush_delay=2
local diff
local retries=20 i=0
while (( (i++) < retries )); do
diff=$(test_max_delay_to_insert_will_succeed_once $flush_delay $max_delay_to_insert)
if (( diff<(flush_delay-1) )); then
echo "max_delay_to_insert was not wait flush_delay ($diff)"
break
if test_max_delay_to_insert_will_succeed_once; then
return
fi
# retry the test until the diff will be satisfied
# (since we cannot assume that there will be no other lags)
if (( diff>=(max_delay_to_insert-1) )); then
continue
fi
return
done
echo "max_delay_to_insert was overcommited ($diff)"
echo failed
}
function run_test()