-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds easy Java setup. Adds testRunner.js and --clearLogs flag.
- Loading branch information
1 parent
6d0cfe0
commit ffad403
Showing
8 changed files
with
167 additions
and
68 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
require('dotenv').config(); | ||
|
||
const shell = require('shelljs'); | ||
|
||
const timesArg = Number(process.argv[2]); | ||
|
||
const RUN_ALL_TESTS_THESE_TIMES = timesArg || Number(process.env.RUN_ALL_TESTS_THESE_TIMES) || 1; | ||
|
||
console.info(`Will attempt to run tests ${RUN_ALL_TESTS_THESE_TIMES} times.`); | ||
|
||
const cleanEnvCommand = "kill $(ps -A | grep -e java -e python -e bitcoind | awk '{print $1}')"; | ||
const runTestsMultipleTimes = (params) => { | ||
|
||
const times = params.times || ''; | ||
const RUN_ALL_TESTS_THESE_TIMES = times || Number(process.env.RUN_ALL_TESTS_THESE_TIMES) || 1; | ||
|
||
console.info(`Will attempt to run tests ${RUN_ALL_TESTS_THESE_TIMES} times.`); | ||
|
||
const cleanEnvCommand = "kill $(ps -A | grep -e java -e python -e bitcoind | awk '{print $1}')"; | ||
|
||
const ensureCleanEnv = () => { | ||
console.info('Cleaning environment...'); | ||
shell.exec(cleanEnvCommand); | ||
console.info('Environment clean.'); | ||
}; | ||
|
||
let fails = 0; | ||
let attempts = 1; | ||
|
||
for(let i = 0; i < RUN_ALL_TESTS_THESE_TIMES; i++) { | ||
console.info(`Running tests ${attempts} out of ${RUN_ALL_TESTS_THESE_TIMES} times.`); | ||
ensureCleanEnv(); | ||
if (shell.exec('npm run test-fail-fast').code !== 0) { | ||
fails++; | ||
} | ||
console.info(`Tests have failed ${fails} times so far.`); | ||
console.info(`Tests have passed ${attempts - fails} times so far.`); | ||
attempts++; | ||
} | ||
|
||
console.info(`Tests failed ${fails} times out of ${RUN_ALL_TESTS_THESE_TIMES} attempts.`); | ||
|
||
const ensureCleanEnv = () => { | ||
console.info('Cleaning environment...'); | ||
shell.exec(cleanEnvCommand); | ||
console.info('Environment clean.'); | ||
}; | ||
|
||
let fails = 0; | ||
let attempts = 1; | ||
|
||
for(let i = 0; i < RUN_ALL_TESTS_THESE_TIMES; i++) { | ||
console.info(`Running tests ${attempts} out of ${RUN_ALL_TESTS_THESE_TIMES} times.`); | ||
ensureCleanEnv(); | ||
if (shell.exec('npm run test-fail-fast').code !== 0) { | ||
fails++; | ||
} | ||
console.info(`Tests have failed ${fails} times so far.`); | ||
console.info(`Tests have passed ${attempts - fails} times so far.`); | ||
attempts++; | ||
} | ||
|
||
console.info(`Tests failed ${fails} times out of ${RUN_ALL_TESTS_THESE_TIMES} attempts.`); | ||
module.exports = { | ||
runTestsMultipleTimes | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,46 @@ | ||
require('dotenv').config(); | ||
|
||
const shell = require('shelljs'); | ||
|
||
const testFileNameWithJsExtension = process.argv[2]; | ||
// Just to make sure we leave everything as we found it | ||
process.env.RUNNING_SINGLE_TEST_FILE = false; | ||
process.env.FORK_NAME = ''; | ||
|
||
const forkName = process.argv[3] || ''; | ||
const runSingleTestFile = (params) => { | ||
|
||
console.log(`Executing test file '${testFileNameWithJsExtension}' in isolation.`); | ||
const { testFileName, forkName = '' } = params; | ||
|
||
if(forkName) { | ||
console.log(`Using fork '${forkName}'.`); | ||
} | ||
if(!testFileName) { | ||
console.error('No test file name provided.'); | ||
return; | ||
} | ||
|
||
// Including this test file to be the only one to be executed | ||
process.env.INCLUDE_CASES = testFileNameWithJsExtension; | ||
if(!testFileName.endsWith('.js')) { | ||
testFileName += '.js'; | ||
return; | ||
} | ||
|
||
// Setting this flag to make the test file know it is being run in isolation and do the necessary adjustments | ||
process.env.RUNNING_SINGLE_TEST_FILE = true; | ||
console.info(`Executing test file '${testFileName}' in isolation.`); | ||
|
||
process.env.FORK_NAME = forkName; | ||
if(forkName) { | ||
console.info(`Using fork '${forkName}'.`); | ||
} | ||
|
||
if (shell.exec('npm run test-fail-fast').code !== 0) { | ||
console.error(`Test file '${testFileNameWithJsExtension}' failed to run.`); | ||
} else { | ||
console.log(`Test file '${testFileNameWithJsExtension}' ran successfully.`); | ||
} | ||
// Including this test file to be the only one to be executed | ||
process.env.INCLUDE_CASES = testFileName; | ||
|
||
// Just to make sure we leave everything as we found it | ||
process.env.RUNNING_SINGLE_TEST_FILE = false; | ||
// Setting this flag to make the test file know it is being run in isolation and do the necessary adjustments | ||
process.env.RUNNING_SINGLE_TEST_FILE = true; | ||
|
||
process.env.FORK_NAME = ''; | ||
process.env.FORK_NAME = forkName; | ||
|
||
if (shell.exec('npm run test-fail-fast').code !== 0) { | ||
console.error(`Test file '${testFileName}' failed to run.`); | ||
} else { | ||
console.info(`Test file '${testFileName}' ran successfully.`); | ||
} | ||
|
||
}; | ||
|
||
module.exports = { | ||
runSingleTestFile | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require('dotenv').config(); | ||
const fs = require('fs').promises; | ||
const shell = require('shelljs'); | ||
|
||
const defaultParamsValues = { | ||
clearLogs: false, | ||
runTestsMultipleTimes: false, | ||
times: 1, | ||
runSingleTestFile: false, | ||
testFileName: '', | ||
forkName: '', | ||
}; | ||
|
||
async function deleteAllFiles(directoryPath) { | ||
try { | ||
await fs.rm(directoryPath, { recursive: true, force: true }); | ||
} catch (err) { | ||
console.error(`Error deleting files: ${err.message}`); | ||
} | ||
}; | ||
|
||
const getParsedParams = () => { | ||
const params = process.argv.filter(param => param.startsWith('--')) | ||
.reduce((params, param) => { | ||
if(param.startsWith('--clearLogs')) { | ||
params.clearLogs = true; | ||
} else if(param.startsWith('--runTestsMultipleTimes')) { | ||
params.runTestsMultipleTimes = true; | ||
} else if(param.startsWith('--times')) { | ||
params.times = param.slice(param.indexOf('=') + 1); | ||
} else if(param.startsWith('--runSingleTestFile')) { | ||
params.runSingleTestFile = true; | ||
} else if(param.startsWith('--testFileName')) { | ||
params.testFileName = param.slice(param.indexOf('=') + 1); | ||
} else if(param.startsWith('--forkName')) { | ||
params.forkName = param.slice(param.indexOf('=') + 1); | ||
} | ||
return params; | ||
}, defaultParamsValues); | ||
return params; | ||
}; | ||
|
||
const runTests = async () => { | ||
|
||
const params = getParsedParams(); | ||
|
||
if(params.clearLogs) { | ||
console.log('Clearing logs...'); | ||
await deleteAllFiles(process.env.LOG_HOME); | ||
} | ||
|
||
if(params.runTestsMultipleTimes) { | ||
const { times } = params; | ||
return require('./multipleTestExecutionsRunner').runTestsMultipleTimes({ times }); | ||
} | ||
|
||
if(params.runSingleTestFile) { | ||
const { testFileName, forkName } = params; | ||
return require('./singleTestFileRunner').runSingleTestFile({ testFileName, forkName }); | ||
} | ||
|
||
if (shell.exec('npm run test-fail-fast').code !== 0) { | ||
console.error(`Tests failed to run.`); | ||
} else { | ||
console.info(`Tests ran successfully.`); | ||
} | ||
|
||
}; | ||
|
||
runTests(); |