From bbf400a83bf0dcf6a73c0aa78727e5cf290b9ea8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 27 Oct 2022 11:19:55 +0200 Subject: [PATCH 1/6] `/proc/cpuinfo` is not available on Darwin arch (ie. mac) --- script/rspec-slow-repeat | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/script/rspec-slow-repeat b/script/rspec-slow-repeat index 797ca46126..649e57f2ba 100755 --- a/script/rspec-slow-repeat +++ b/script/rspec-slow-repeat @@ -15,7 +15,17 @@ fi n="$1" passed=0 -processors="`cat /proc/cpuinfo | grep -c processor`" + +# 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 & From 84831266f1587acecd15a32936812351b99930bc Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 31 Oct 2022 10:19:02 +0100 Subject: [PATCH 2/6] Remove useless information --- script/rspec-slow-repeat | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/script/rspec-slow-repeat b/script/rspec-slow-repeat index 649e57f2ba..0202c8da33 100755 --- a/script/rspec-slow-repeat +++ b/script/rspec-slow-repeat @@ -19,13 +19,11 @@ 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" +echo "Running $n times with $processors cores" for i in `seq $processors`; do yes > /dev/null & From 0eff4d39064a66ac6c62a09e8a87b6269ee75444 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 31 Oct 2022 10:19:36 +0100 Subject: [PATCH 3/6] Add some comment on the purpose --- script/rspec-slow-repeat | 3 +++ 1 file changed, 3 insertions(+) diff --git a/script/rspec-slow-repeat b/script/rspec-slow-repeat index 0202c8da33..081408f3f6 100755 --- a/script/rspec-slow-repeat +++ b/script/rspec-slow-repeat @@ -25,6 +25,9 @@ fi echo "Running $n times with $processors cores" +# The purpose here is to occupy the CPU (yes command is not multi-threaded and it occupies only one core) +# Start one process for each core, and then simulating a very busy CI environment with a 100% CPU load +# increasing the chance of race conditions when executing specs. for i in `seq $processors`; do yes > /dev/null & done From 9ba0695652a57a95cf4b5f34497413c8dde9ce48 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 31 Oct 2022 11:25:21 +0100 Subject: [PATCH 4/6] Trap CTRL+C to exit all yes commands --- script/rspec-slow-repeat | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/script/rspec-slow-repeat b/script/rspec-slow-repeat index 081408f3f6..87588a568c 100755 --- a/script/rspec-slow-repeat +++ b/script/rspec-slow-repeat @@ -7,6 +7,14 @@ # 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. +function finish() { + echo "Exiting..." + killall yes + exit 0 +} + +trap finish SIGINT + if [ "$#" -lt 1 ]; then echo "Usage: $0 [rspec params]" echo "Example: $0 30 spec/system/admin/order_cycles/simple_spec.rb:202" @@ -44,7 +52,7 @@ for i in `seq "$n"`; do fi done -killall yes - pass_rate="$(( passed * 100 / n))" echo "$passed of $n passed ($pass_rate%)" + +finish From b93f6dfdadbdd904511d467ec03a4c8d20452390 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 31 Oct 2022 16:10:48 +0100 Subject: [PATCH 5/6] Add convenient logging when failing --- script/rspec-slow-repeat | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/script/rspec-slow-repeat b/script/rspec-slow-repeat index 87588a568c..155e25d8bb 100755 --- a/script/rspec-slow-repeat +++ b/script/rspec-slow-repeat @@ -10,7 +10,12 @@ function finish() { echo "Exiting..." killall yes - exit 0 + if [ "$pass_rate" -lt 100 ]; then + echo "Check tmp/rspec.log for details." + exit 1 + else + exit 0 + fi } trap finish SIGINT From 3ff1cd079333bcdfad769ef6b5d737ee97ef812c Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 31 Oct 2022 16:11:19 +0100 Subject: [PATCH 6/6] Prefer to killall descendants instead of just killing yes processes --- script/rspec-slow-repeat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/rspec-slow-repeat b/script/rspec-slow-repeat index 155e25d8bb..529e2e9489 100755 --- a/script/rspec-slow-repeat +++ b/script/rspec-slow-repeat @@ -9,7 +9,7 @@ function finish() { echo "Exiting..." - killall yes + pkill -P $$ if [ "$pass_rate" -lt 100 ]; then echo "Check tmp/rspec.log for details." exit 1