Created
June 14, 2017 04:10
-
-
Save stelcheck/f755803ef178c2fb2706be9695c3de77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function printResult() { | |
echo "" | |
echo "==============================" | |
[[ ${1} == 0 ]] && echo "success" || echo "failed" | |
echo "==============================" | |
} | |
dirPath=/tmp/a/b/c/aaaaaaaa/b/c/c/d/d/d/d/d/d/d/d/d/d/d/d/d/d/d/d/d/d/d/allyourbasearebelongtous/ | |
read -r -d '' jsSource << EOF | |
const net = require('net') | |
const fs = require('fs') | |
const path = require('path') | |
const SOCK_FILE = path.join(__dirname, 'file.sock') | |
console.log('Sock file located at:', SOCK_FILE) | |
try { | |
fs.unlinkSync(SOCK_FILE) | |
} catch (error) { | |
console.log('failed to remove sock file', error.message, error.code) | |
} | |
net.createServer(() => true).listen(SOCK_FILE, () => setTimeout(() => process.exit(), 1000)) | |
EOF | |
echo "" | |
echo "-- Creating Directory" | |
mkdir -p "${dirPath}" | |
pushd "${dirPath}" | |
echo "${jsSource}" > index.js | |
echo "" | |
echo "------------------------------------------------------------" | |
echo "-- Starting server for the first time - should exit properly" | |
echo "------------------------------------------------------------" | |
echo "" | |
node index.js | |
printResult ${?} | |
echo "" | |
echo "-----------------------------------------------------" | |
echo "-- Starting server for the second time - should crash" | |
echo "-----------------------------------------------------" | |
echo "" | |
node index.js | |
printResult ${?} | |
echo "" | |
echo "-- Cleaning up" | |
popd | |
rm -rf "${dirPath}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment