Skip to content

Instantly share code, notes, and snippets.

@watson
Last active January 27, 2022 10:55
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watson/493f359315e7542ddcad37b3408b9f5e to your computer and use it in GitHub Desktop.
Save watson/493f359315e7542ddcad37b3408b9f5e to your computer and use it in GitHub Desktop.
Automated git bisect to find breaking commit in Node core. This example was used to find a specific issue, so it should of course be modified to fit your needs. These files are ment to be put inside the root of your locally cloned node repo.
#!/usr/bin/env bash
# This script is an easy way to bisect between two releases of Node.js
if [ $# -ne 2 ]; then
echo "Error: No arguments supplied!"
echo "Usage:"
echo " ./bisect.sh <git-ref> <git-ref>"
echo
echo "Example:"
echo " ./bisect.sh v7.9.0 v8.0.0"
exit 1
fi
parent=`git merge-base $1 $2`
echo Common parent for $1 and $2: $parent
git bisect start $2 $parent
git bisect run ./build-and-test.sh
#!/usr/bin/env bash
# Compile the currently checked out version of Node.js.
# This expects to run on 72 cores (a c5.18xlarge EC2 instance).
# Modify the -j72 line according to the number of CPU cores you have available.
# Exit code 125 means that this version cannot be tested and it will be skipped.
./configure &> /dev/null || exit 125;
make -j72 &> /dev/null || exit 125;
# Run the actual test
# If it exits with code 0, it means that it was successfull
# If it exits with code 125, it means that it should be skipped
# If it exits with any other code, it means that it failed
echo Running tests for Node.js version: `./node -v`
./test-current-node.sh
exit_code=$?
echo Exit code: $exit_code
exit $exit_code
#!/usr/bin/env bash
# This script allows us to run the same command in parallel multiple times.
# If one of the executions of the command fails with a non zero exit code,
# the program will terminate the remaining jobs and exit with that exit code
# trap for SIGTERM and set RET_VALUE to false
trap "RET_VAL=false" SIGTERM
MY_PID=$$
# Initialize RET_VALUE to true
RET_VAL=true
# This function will executed be in a separate job (see below)
thread_listener() {
# Starts test in the background
curl -s http://localhost:1337 > /dev/null &
PID=$!
# trap for sigterm and kill the long time process
trap "kill $PID" SIGTERM
echo waiting for $PID
echo Parent $MY_PID
# Send a SIGTERM to parent job in case of failure
wait $PID || kill $MY_PID
exit
}
echo $MY_PID
# Runs thread listener in a separate job
thread_listener &
PID1=$!
# Runs thread listener in a separate job
thread_listener &
PID2=$!
wait
# send sigterm to PID1 and PID2 if present
kill $PID1 2> /dev/null
kill $PID2 2> /dev/null
# returns RET_VALUE
$RET_VAL
'use strict'
var http = require('http')
var send = require('send')
var n = 0
http.createServer(function (req, res) {
send(req, __filename).pipe(res)
// The error we're investigating will happen during the 2nd request.
// So this server will automatically shut down after it have received two requests,
// in which case all was good.
req.on('end', function () {
if (++n === 2) {
process.nextTick(function () {
process.exit()
})
}
})
}).listen(1337)
#!/usr/bin/env bash
# In case of race conditions, we run the same test 5 times.
# Only if they all pass we consider it a success.
# You can change the number "5" below according to your specific needs
for i in `seq 1 5`;
do
echo Attempt number $i
# This test need a running Node.js HTTP server
./node server.js &
# Ensure that the server is ready by waiting a little
sleep 1
# Make some concurrent HTTP requests to the server.
# In this example, the server might shut down,
# in which case the current version of Node.js contains the bug we're looking for,
# so we exit with a non zero exit code
./make-concurrent-requests.sh || exit $?
done
echo All attempts was successfull. This must be a good build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment