node-minecraft-protocol/test/common/parallel.js

21 lines
1,005 B
JavaScript
Raw Normal View History

const nodeIndex = parseInt(process.env.CIRCLE_NODE_INDEX)
const nodeTotal = parseInt(process.env.CIRCLE_NODE_TOTAL)
const parallel = process.env.CIRCLE_NODE_INDEX !== undefined && process.env.CIRCLE_NODE_TOTAL !== undefined
const mc = require('../../')
// expected values :
// (0,4,10) -> (0,2)
// (1,4,10) -> (3,5)
// (2,4,10) -> (6,8)
// (3,4,10) -> (9,9)
function testedRange (nodeIndex, nodeTotal, numberOfVersions) {
const nbFirsts = Math.ceil(numberOfVersions / nodeTotal)
2018-09-24 16:07:34 -04:00
if (nodeIndex === (nodeTotal - 1)) { return { firstVersion: nbFirsts * nodeIndex, lastVersion: numberOfVersions - 1 } }
2018-09-24 16:07:34 -04:00
return { firstVersion: nodeIndex * nbFirsts, lastVersion: (nodeIndex + 1) * nbFirsts - 1 }
}
2018-09-24 16:07:34 -04:00
console.log({ nodeIndex, nodeTotal, versions: mc.supportedVersions.length })
const { firstVersion, lastVersion } = parallel ? testedRange(nodeIndex, nodeTotal, mc.supportedVersions.length) : { firstVersion: 0, lastVersion: mc.supportedVersions.length - 1 }
2018-09-24 16:07:34 -04:00
module.exports = { firstVersion, lastVersion }