Skip to content

Commit

Permalink
Merge pull request #357 from step2yeung/completebrowsers
Browse files Browse the repository at this point in the history
Improve complete browser book keeping & improve request next module conditions
  • Loading branch information
step2yeung authored Sep 11, 2019
2 parents 2121b28 + e51b0f4 commit 662719a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
6 changes: 6 additions & 0 deletions addon-test-support/-private/ember-exam-qunit-test-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ export default class EmberExamQUnitTestLoader extends TestLoader {
});

const nextModuleHandler = () => {
// if there are already tests queued up, don't request next module
// this is possible if a test file has multiple qunit modules
if (this._qunit.config.queue.length > 0) {
return;
}

return nextModuleAsyncIterator
.next()
.then((response) => {
Expand Down
11 changes: 6 additions & 5 deletions lib/commands/exam.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,25 +268,26 @@ module.exports = TestCommand.extend({
const ui = this.ui;
const events = config.custom_browser_socket_events || {};
const testExecutionFileName = `test-execution-${Date.now()}.json`;
const browserCount = Object.keys(config.testPage).length;
const browserExitHandler = function() {
const browserCount = Object.keys(config.testPage).length;
const browserId = getBrowserId(this.launcher.settings.test_page);

testemEvents.completedBrowsersHandler(
browserCount,
browserId,
ui,
commands.get('loadBalance'),
testExecutionFileName,
commands.get('writeExecutionFile')
);
};
const browserFailureHandler = function() {
if (this.finished) {
return;
} else if (commands.get('writeExecutionFile')) {
if (commands.get('writeExecutionFile')) {
const browserId = getBrowserId(this.launcher.settings.test_page);
testemEvents.recordFailedBrowserId(browserId);
}

browserExitHandler();
browserExitHandler.call(this);
};

let init = false;
Expand Down
12 changes: 7 additions & 5 deletions lib/utils/execution-state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ExecutionStateManager {

// An array keeping the browserId of a browser with failing test
this._failedBrowsers = [];
this._completedBrowsers = 0;
this._completedBrowsers = new Map();

// An array of modules to load balance against browsers. This is used by `--load-balance`
this._testModuleQueue = null;
Expand Down Expand Up @@ -171,14 +171,16 @@ class ExecutionStateManager {
* @returns {number}
*/
getCompletedBrowser() {
return this._completedBrowsers;
return this._completedBrowsers.size;
}

/**
* Increment the number of completed browsers
* Book keep the browser id that has completed
*
* @param {number} browserId
*/
incrementCompletedBrowsers() {
this._completedBrowsers = this._completedBrowsers + 1;
incrementCompletedBrowsers(browserId) {
this._completedBrowsers.set(browserId, true);
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/utils/testem-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,16 @@ class TestemEvents {
* When all browsers complete, write test-execution.json to disk and clean up the stateManager
*
* @param {number} browserCount
* @param {number} browserid
* @param {Object} ui
* @param {boolean} loadBalance
* @param {string} fileName
* @param {string} writeExecutionFile
*/
completedBrowsersHandler(browserCount, ui, loadBalance, fileName, writeExecutionFile) {
completedBrowsersHandler(browserCount, browserId, ui, loadBalance, fileName, writeExecutionFile) {
let browsersCompleted = false;

this.stateManager.incrementCompletedBrowsers();
this.stateManager.incrementCompletedBrowsers(browserId);
if (this.stateManager.getCompletedBrowser() === browserCount) {
if (writeExecutionFile && loadBalance) {
const moduleMapJson = this._generatesModuleMapJsonObject(browserCount);
Expand Down
9 changes: 9 additions & 0 deletions node-tests/unit/utils/execution-state-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,13 @@ describe('ExecutionStateManager', function() {
);
});
});

describe('completedBrowsers', function() {
it('incrementCompletedBrowsers called for the same browserId will only be accounted once', function() {
this.stateManager.incrementCompletedBrowsers(1);
this.stateManager.incrementCompletedBrowsers(1);

assert.deepEqual(this.stateManager.getCompletedBrowser(), 1);
});
});
});
5 changes: 5 additions & 0 deletions node-tests/unit/utils/testem-events-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ describe('TestemEvents', function() {
it('should increment completedBrowsers only when completedBrowsers is less than browserCount', function() {
this.testemEvents.completedBrowsersHandler(
2,
1,
mockUi,
true,
'test-execution.json',
Expand All @@ -196,6 +197,7 @@ describe('TestemEvents', function() {
it('should write test-execution file and cleanup state when completedBrowsers equals browserCount and load-balance is true', function() {
this.testemEvents.stateManager.addModuleNameToReplayExecutionMap('a', 1);
this.testemEvents.completedBrowsersHandler(
1,
1,
mockUi,
true,
Expand All @@ -219,6 +221,7 @@ describe('TestemEvents', function() {
it('should increment completedBrowsers when load-balance is false', function() {
this.testemEvents.completedBrowsersHandler(
2,
1,
mockUi,
false,
'test-execution.json',
Expand All @@ -238,6 +241,7 @@ describe('TestemEvents', function() {

this.testemEvents.completedBrowsersHandler(
2,
1,
mockUi,
true,
'test-execution.json',
Expand All @@ -254,6 +258,7 @@ describe('TestemEvents', function() {
mockReplayExecutionMap
);
this.testemEvents.completedBrowsersHandler(
1,
1,
mockUi,
true,
Expand Down

0 comments on commit 662719a

Please sign in to comment.