2020-06-11 21:25:18 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-01-24 01:02:07 +00:00
|
|
|
# SPDX-FileCopyrightText: 2021-2024 Ole Tange, http://ole.tange.dk and Free Software and Foundation, Inc.
|
2021-03-22 20:16:35 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-06-11 21:25:18 +00:00
|
|
|
# GNU Parallel SQL tests
|
|
|
|
# The tests must be able to run in parallel
|
|
|
|
|
2024-06-16 10:37:14 +00:00
|
|
|
me=$(whoami)
|
2020-06-11 21:25:18 +00:00
|
|
|
export SQLITE=sqlite3:///%2Frun%2Fshm%2Fparallel.db
|
2024-06-16 10:37:14 +00:00
|
|
|
export PG=pg://$me:$me@localhost/$me
|
|
|
|
export MYSQL=mysql://$me:$me@/$me
|
2020-06-11 21:25:18 +00:00
|
|
|
export CSV=csv:///%2Frun%2Fshm%2Fcsv
|
|
|
|
|
|
|
|
rm -f /run/shm/parallel.db
|
|
|
|
mkdir -p /run/shm/csv
|
|
|
|
|
|
|
|
par_few_duplicate_run() {
|
|
|
|
echo '### With many workers there will be some duplicates'
|
|
|
|
TABLE=TBL$RANDOM
|
|
|
|
DBURL="$1"/$TABLE
|
|
|
|
parallel --sqlmaster $DBURL echo ::: {1..100}
|
|
|
|
lines=$( (
|
|
|
|
parallel --sqlworker $DBURL &
|
|
|
|
parallel --sqlworker $DBURL &
|
|
|
|
parallel --sqlworker $DBURL &
|
|
|
|
parallel --sqlworker $DBURL &
|
|
|
|
wait
|
|
|
|
) | wc -l)
|
2020-09-23 15:41:03 +00:00
|
|
|
sql "$1" "drop table $TABLE;"
|
2023-01-30 21:51:56 +00:00
|
|
|
if [ $lines -gt 110 ] ; then
|
|
|
|
echo Error: $lines are more than 10% duplicates
|
2020-06-11 21:25:18 +00:00
|
|
|
else
|
|
|
|
echo OK
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
hostname=`hostname`
|
|
|
|
export -f $(compgen -A function | egrep 'p_|par_')
|
|
|
|
# Tested that -j0 in parallel is fastest (up to 15 jobs)
|
|
|
|
compgen -A function | grep par_ | sort |
|
|
|
|
stdout parallel -vj5 -k --tag --joblog /tmp/jl-`basename $0` {1} {2} \
|
|
|
|
:::: - ::: \$CSV \$MYSQL \$PG \$SQLITE |
|
|
|
|
perl -pe 's/tbl\d+/TBL99999/gi;' |
|
|
|
|
perl -pe 's/(from TBL99999 order) .*/$1/g' |
|
|
|
|
perl -pe 's/ *\b'"$hostname"'\b */hostname/g' |
|
|
|
|
grep -v -- --------------- |
|
|
|
|
perl -pe 's/ *\bhost\b */host/g' |
|
|
|
|
perl -pe 's/ +/ /g'
|
|
|
|
|