Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should fail the test cases split to a browser that is disconnected #38 #43

Merged
merged 1 commit into from Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 70 additions & 3 deletions lib/framework.js
Expand Up @@ -4,6 +4,8 @@ const path = require('path');

// jshint node: true

let disconnectedBrowser;

function getConfig(fullConfig) {
// ensure we can manipulate config settings
const config = (fullConfig.parallelOptions =
Expand Down Expand Up @@ -62,6 +64,7 @@ function setBrowserCount(config, browsers, log) {
// if we restart our browsers or if connections get reset.
function handleBrowserRegister(log, config, browser) {
// Create a alias Id for each browser.name. Used in identifying coverage reports

config.browserIdAlias[browser.name] =
config.browserIdAlias[browser.name] ||
Math.floor(Math.random() * Date.now());
Expand Down Expand Up @@ -97,7 +100,71 @@ module.exports = function(/* config */ fullConfig, emitter, logger) {
const config = getConfig(fullConfig);
setupMiddleware(log, fullConfig);
setBrowserCount(config, fullConfig.browsers, log);
emitter.on('browser_register', browser =>
handleBrowserRegister(log, config, browser)
);
emitter.on('browser_register', (browser) => {
log.debug('disconnectedBrowser', disconnectedBrowser);

// If there is disconnected browser
if (disconnectedBrowser) {
disconnectedBrowser = false;
const currentShardedIndexes = [];
const expectedShardedIndexes = [];

for (let i = 0; i < config.executors; i++) {
expectedShardedIndexes.push(i);
}

Object.keys(config.shardIndexMap)
.forEach((key) => {
currentShardedIndexes.push(config.shardIndexMap[key]);
});

// Get missing executr index
log.debug('currentShardedIndexes, expectedShardedIndexes', currentShardedIndexes, expectedShardedIndexes);
const diff = arr_diff(currentShardedIndexes, expectedShardedIndexes);
log.debug('shard index', diff);

if (diff.length !== 0) {
// Re-register the browser with valid shard id.
config.shardIndexMap[browser.id] = diff[0];
log.debug(
`Re - registering browser id ${browser.id} with aggregated browser id ${
config.browserIdAlias[browser.name]
} at shard index ${config.shardIndexMap[browser.id]}`
);

log.debug('SHARDEDINFO', config.shardIndexMap);
}
} else {
handleBrowserRegister(log, config, browser);
}
});

emitter.on('browser_error', (browser, data) => {
delete config.shardIndexMap[browser.id];

disconnectedBrowser = true;
log.debug('browser_error', browser, data);
});
};

function arr_diff (a1, a2) {
const a = [], diff = [];

for (let i = 0; i < a1.length; i++) {
a[a1[i]] = true;
}

for (let i = 0; i < a2.length; i++) {
if (a[a2[i]]) {
delete a[a2[i]];
} else {
a[a2[i]] = true;
}
}

for (let k in a) {
diff.push(k);
}

return diff;
}
4 changes: 2 additions & 2 deletions lib/karma-parallelizer.js
Expand Up @@ -56,7 +56,7 @@ function createDescriptionLengthStrategy(shardIndexInfo) {
var shardIndex = shardIndexInfo.shardIndex,
executors = shardIndexInfo.executors;
return function overrideSpecSuite(description /*, specDefinitions*/) {
return description.length % executors === shardIndex;
return Number(description.length % executors) === Number(shardIndex);
};
}

Expand All @@ -81,7 +81,7 @@ function createRoundRobinStrategy(shardIndexInfo) {
// round-robin responsibility
var count = 0;
return function(/*description, specDefinitions*/) {
return count++ % executors === shardIndex;
return Number(count++ % executors) === Number(shardIndex);
};
}

Expand Down