mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
50 lines
1.1 KiB
Bash
Executable File
50 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# If you suspect that a spec becomes flaky on slow machines:
|
|
#
|
|
# ./script/rspec-slow-repeat 10 spec/system/some_flaky_spec.rb
|
|
#
|
|
# You can use the resulting pass rate to asses if your code changes fixed it
|
|
# or not. In the end I would run a spec 100 times to be sure it's stable.
|
|
|
|
if [ "$#" -lt 1 ]; then
|
|
echo "Usage: $0 <n> [rspec params]"
|
|
echo "Example: $0 30 spec/system/admin/order_cycles/simple_spec.rb:202"
|
|
exit 1
|
|
fi
|
|
|
|
n="$1"
|
|
passed=0
|
|
|
|
# Check via uname the environment we are running in to get the number of cores
|
|
if [[ "`uname`" == "Darwin" ]]; then
|
|
processors="`sysctl -n hw.ncpu.`"
|
|
env="mac"
|
|
else
|
|
processors="`cat /proc/cpuinfo | grep -c processor`"
|
|
env="linux"
|
|
fi
|
|
|
|
echo "Running $n times on a $env with $processors cores"
|
|
|
|
for i in `seq $processors`; do
|
|
yes > /dev/null &
|
|
done
|
|
|
|
export RUBY_DEBUG_ENABLE=0
|
|
export SPRING_QUIET=true
|
|
|
|
for i in `seq "$n"`; do
|
|
if ./bin/rspec "${@:2}" >> tmp/rspec.log; then
|
|
echo "Pass."
|
|
(( passed++ ))
|
|
else
|
|
echo " !!! Fail !!!"
|
|
fi
|
|
done
|
|
|
|
killall yes
|
|
|
|
pass_rate="$(( passed * 100 / n))"
|
|
echo "$passed of $n passed ($pass_rate%)"
|