Skip to content

Commit

Permalink
Some CT server work for #88
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Apr 15, 2020
1 parent 2d4ddef commit 23426e9
Show file tree
Hide file tree
Showing 6 changed files with 504 additions and 11 deletions.
1 change: 1 addition & 0 deletions html/continuous-report.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ <h1>Continuous Testing Results</h1>

<div id="report-container">
</div>
<script src="../../query-string-machine/js/QueryStringMachine.js"></script>
<script src="../js/continuous-report.js"></script>
</body>
</html>
143 changes: 143 additions & 0 deletions js/CTSnapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Copyright 2020, University of Colorado Boulder

/**
* Holds data related to a CT snapshot
*
* @author Jonathan Olson <[email protected]>
*/

'use strict';

const copyDirectory = require( '../../perennial/js/common/copyDirectory' );
const createDirectory = require( '../../perennial/js/common/createDirectory' );
const deleteDirectory = require( '../../perennial/js/common/deleteDirectory' );
const execute = require( '../../perennial/js/common/execute' );
const getRepoList = require( '../../perennial/js/common/getRepoList' );
const gitRevParse = require( '../../perennial/js/common/gitRevParse' );
const npmCommand = require( '../../perennial/js/common/npmCommand' );
const fs = require( 'fs' );
const _ = require( 'lodash' ); // eslint-disable-line

// constants
const copyOptions = { filter: path => path.indexOf( 'node_modules' ) < 0 };

class CTSnapshot {
/**
* Creates this snapshot.
* @public
*
* @param {string} rootDir
* @param {function({string})} setSnapshotStatus
*/
async create( rootDir, setSnapshotStatus ) {

// @private {string}
this.rootDir = rootDir;

// @private {function}
this.setSnapshotStatus = setSnapshotStatus;

const timestamp = Date.now();
const snapshotDir = `${rootDir}/ct-snapshots`;

this.setSnapshotStatus( `Initializing new snapshot: ${timestamp}` );

// @public {number}
this.timestamp = timestamp;

// @public {string}
this.name = `snapshot-${timestamp}`;

// @public {boolean}
this.exists = true;

// @public {string}
this.phetDir = `${snapshotDir}/${timestamp}-phet`;
this.phetioDir = `${snapshotDir}/${timestamp}-phet-io`;

if ( !fs.existsSync( snapshotDir ) ) {
await createDirectory( snapshotDir );
}
await createDirectory( this.phetDir );
await createDirectory( this.phetioDir );

this.setSnapshotStatus( 'Copying snapshot files' );

// @public {Array.<string>}
this.repos = getRepoList( 'active-repos' );

// @public {Array.<string>}
this.npmInstalledRepos = [];

// @public {Object} - maps repo {string} => sha {string}
this.shas = {};
for ( const repo of this.repos ) {
this.shas[ repo ] = await gitRevParse( repo, 'master' );
}

for ( const repo of this.repos ) {
await copyDirectory( `${rootDir}/${repo}`, `${this.phetDir}/${repo}`, copyOptions );
await copyDirectory( `${rootDir}/${repo}`, `${this.phetioDir}/${repo}`, copyOptions );
}

// @public {Array.<Object>}
this.tests = JSON.parse( await execute( 'node', [ 'js/listContinuousTests.js' ], '../perennial' ) ).map( test => {
test.snapshot = this;
return test;
} );
this.browserTests = this.tests.filter( test => [ 'sim-test', 'qunit-test', 'pageload-test' ].includes( test.type ) ).map( test => {
test.count = 0;
return test;
} );
this.lintTests = this.tests.filter( test => test.type === 'lint' ).map( test => {
test.complete = false;
return test;
} );
this.buildTests = this.tests.filter( test => test.type === 'build' ).map( test => {
test.complete = false;
test.success = false;
return test;
} );
}

async npmInstall() {
const npmRepos = this.repos.filter( repo => fs.existsSync( `../${repo}/package.json` ) );
for ( const repo of npmRepos ) {
this.setSnapshotStatus( `Running npm update for ${repo}` );

await execute( npmCommand, [ 'update', `--cache=../npm-caches/${repo}`, '--tmp=../npm-tmp' ], `${this.phetDir}/${repo}` );
await execute( npmCommand, [ 'update', `--cache=../npm-caches/${repo}`, '--tmp=../npm-tmp' ], `${this.phetioDir}/${repo}` );
}
}

/**
* Removes the snapshot's files.
* @public
*/
async remove() {
await deleteDirectory( this.phetDir );
await deleteDirectory( this.phetioDir );

this.exists = false;
}

getAvailableBrowserTests( es5Only ) {
return this.browserTests.filter( test => {
if ( es5Only && !test.es5 ) {
return false;
}

if ( test.buildDependencies ) {
for ( const dependency of test.buildDependencies ) {
if ( !_.some( this.buildTests, buildTest => buildTest.repo === dependency && buildTest.brand === test.brand && buildTest.success ) ) {
return false;
}
}
}

return true;
} );
}
}

module.exports = CTSnapshot;
13 changes: 8 additions & 5 deletions js/continuous-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ const options = QueryStringMachine.getAll( {
},
old: {
type: 'flag'
},
server: {
type: 'string',

// Ignore current port, keep protocol and host.
defaultValue: window.location.protocol + '//' + window.location.hostname
}
} );

// Ignore current port, keep protocol and host.
const serverOrigin = window.location.protocol + '//' + window.location.hostname;

// iframe that will contain qunit-test.html/sim-test.html/etc.
const iframe = document.createElement( 'iframe' );
iframe.setAttribute( 'frameborder', '0' );
Expand Down Expand Up @@ -85,7 +88,7 @@ function nextTest() {
// On connection failure, just try again with a delay (don't hammer the server)
setTimeout( nextTest, 60000 ); // 1min
};
req.open( 'get', serverOrigin + '/aquaserver/next-test?old=' + options.old, true );
req.open( 'get', options.server + '/aquaserver/next-test?old=' + options.old, true );
req.send();
resetTimer();
}
Expand All @@ -108,7 +111,7 @@ function sendTestResult( names, message, testInfo, passed ) {
message: message,
id: options.id
};
req.open( 'get', serverOrigin + '/aquaserver/test-result?result=' + encodeURIComponent( JSON.stringify( result ) ) );
req.open( 'get', options.server + '/aquaserver/test-result?result=' + encodeURIComponent( JSON.stringify( result ) ) );
req.send();
resetTimer();
}
Expand Down
16 changes: 11 additions & 5 deletions js/continuous-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@

'use strict';

// Origin for our server (ignoring current port), so that we don't require localhost
const serverOrigin = window.location.protocol + '//' + window.location.hostname;
const options = QueryStringMachine.getAll( {
server: {
type: 'string',

// Origin for our server (ignoring current port), so that we don't require localhost
defaultValue: window.location.protocol + '//' + window.location.hostname
}
} );

/**
* Returns a CSS class to use given the number of passing results and failing results.
Expand Down Expand Up @@ -311,7 +317,7 @@ function recursiveResults( name, resultNode, snapshots, padding, path ) {
setTimeout( mainLoop, 3000 );
console.log( 'XHR error?' );
};
req.open( 'get', serverOrigin + '/aquaserver/results', true ); // enable CORS
req.open( 'get', options.server + '/aquaserver/results', true ); // enable CORS
req.send();
})();

Expand All @@ -329,7 +335,7 @@ function recursiveResults( name, resultNode, snapshots, padding, path ) {
element.innerHTML = '<span style="color: red;">Could not contact server</span>';
console.log( 'XHR error?' );
};
req.open( 'get', serverOrigin + '/aquaserver/snapshot-status', true ); // enable CORS
req.open( 'get', options.server + '/aquaserver/snapshot-status', true ); // enable CORS
req.send();
})();

Expand All @@ -347,6 +353,6 @@ function recursiveResults( name, resultNode, snapshots, padding, path ) {
element.innerHTML = '<span style="color: red;">Could not contact server</span>';
console.log( 'XHR error?' );
};
req.open( 'get', serverOrigin + '/aquaserver/test-status', true ); // enable CORS
req.open( 'get', options.server + '/aquaserver/test-status', true ); // enable CORS
req.send();
})();
Loading

0 comments on commit 23426e9

Please sign in to comment.