Marcoil has uploaded a new change for review.
https://gerrit.wikimedia.org/r/76754
Change subject: Use a local settings file for rt-test server.js, add more
options.
......................................................................
Use a local settings file for rt-test server.js, add more options.
The round-trip test server will now read a server.settings.js file for its
options, including MySQL connection settings. The command line options
can still be used and they will override those present in the file.
There are also 3 new configuration parameters:
- 'tries' establishes the number of times a title is tested for a commit hash
before it's considered an error.
- 'fetches' sets the number of fetching errors that will be accepted before
the title is no longer considered for testing.
- 'cutofftime' represents, in seconds, the time to wait for a valid response
from a client.
Bug: 52114
Change-Id: If877269980931157ee2e94996edfa4e473a6f610
---
M .gitignore
M .jshintignore
M js/tests/README
M js/tests/server/importJson.js
M js/tests/server/server.js
A js/tests/server/server.settings.js.example
6 files changed, 150 insertions(+), 42 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/54/76754/1
diff --git a/.gitignore b/.gitignore
index cbbd961..670f070 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,4 +13,7 @@
js/api/npm-debug.log
js/node_modules/
js/tests/parserTests.cache
+js/tests/client/config.js
+js/tests/server/node_modules
+js/tests/server/server.settings.js
js/doc
diff --git a/.jshintignore b/.jshintignore
index d11a3c8..801790c 100644
--- a/.jshintignore
+++ b/.jshintignore
@@ -2,3 +2,4 @@
js/node_modules
js/api/scripts/jquery.js
js/doc
+js/tests/server/node_modules
diff --git a/js/tests/README b/js/tests/README
index 1f67e8a..197b0a7 100644
--- a/js/tests/README
+++ b/js/tests/README
@@ -27,11 +27,13 @@
In 'js/tests/server/', to install the necessary packages, run
$ npm install
-You'll need a pre-created MySQL database. You can view the connection options
-and their default values with
+You'll need a pre-created MySQL database. Then, copy server.settings.js.example
+to server.settings.js and in that file edit the connection parameters. You can
+also override the settings with command line options, to see them and their
+default values run
$ node server --help
-Then, to populate the database with the initial data, run
+To populate the database with initial data, run
$ mysql [connection parameters] < sql/create_everything.mysql
$ node importJson --prefix=en titles.example.en.json
@@ -45,9 +47,12 @@
Now start the server:
- $ node server pages.db
+ $ node server
-And in separate windows, as many as you want:
+== Running the round-trip test clients ==
+
+In js/tests/client, copy config.example.js to config.js and edit it to your
+taste. In separate windows, as many as you want:
$ node js/tests/client/client.js
diff --git a/js/tests/server/importJson.js b/js/tests/server/importJson.js
index 84925a7..d95428b 100755
--- a/js/tests/server/importJson.js
+++ b/js/tests/server/importJson.js
@@ -4,8 +4,27 @@
* A utility for reading in a JSON-y list of articles to the database.
*/
-var opts = require( 'optimist' )
- .usage( 'Usage: ./importJson.js titles.example.json' )
+var optimist = require( 'optimist' );
+
+// Default options
+var defaults = {
+ 'host': 'localhost',
+ 'port': 3306,
+ 'database': 'parsoid',
+ 'user': 'parsoid',
+ 'password': 'parsoidpw',
+};
+
+// Settings file
+var settings;
+try {
+ settings = require( './server.settings.js' );
+} catch ( e ) {
+ settings = {};
+}
+
+// Command line options
+var argv = optimist.usage( 'Usage: ./importJson.js titles.example.json' )
.options( 'help', {
description: 'Show this message',
'boolean': true,
@@ -18,39 +37,43 @@
} )
.options( 'h', {
alias: 'host',
- 'default': 'localhost',
describe: 'Hostname of the database server.'
} )
.options( 'P', {
alias: 'port',
- 'default': 3306,
describe: 'Port number to use for connection.'
} )
.options( 'D', {
alias: 'database',
- 'default': 'parsoid',
describe: 'Database to use.'
} )
.options( 'u', {
alias: 'user',
- 'default': 'parsoid',
describe: 'User for login.'
} )
.options( 'p', {
alias: 'password',
- 'default': 'parsoidpw',
describe: 'Password.'
} )
.demand( 1 )
.argv;
+if ( argv.help ) {
+ optimist.showHelp();
+ process.exit( 0 );
+}
+
+var getOption = function( opt ) {
+ return argv[ opt ] || settings[ opt ] || defaults[ opt ];
+};
+
var mysql = require( 'mysql' );
var db = mysql.createConnection({
- host : opts.host,
- port : opts.port,
- database : opts.database,
- user : opts.user,
- password : opts.password,
+ host : getOption( 'host' ),
+ port : getOption( 'port' ),
+ database : getOption( 'database' ),
+ user : getOption( 'user' ),
+ password : getOption( 'password' ),
multipleStatements : true
});
@@ -95,11 +118,11 @@
if ( err ) {
console.error( err );
} else {
- filepath = opts._[0];
+ filepath = argv._[0];
if ( !filepath.match( /^\// ) ) {
filepath = './' + filepath;
}
- loadJSON( filepath, opts );
+ loadJSON( filepath, argv );
db.end();
}
} );
diff --git a/js/tests/server/server.js b/js/tests/server/server.js
index c1b1519..fe82e59 100755
--- a/js/tests/server/server.js
+++ b/js/tests/server/server.js
@@ -3,50 +3,74 @@
"use strict";
var express = require( 'express' ),
- optimist = require( 'optimist' ),
- // The maximum number of tries per article
- maxTries = 6,
- // The maximum number of fetch retries per article
- maxFetchRetries = 6;
+ optimist = require( 'optimist' );
+
+// Default options
+var defaults = {
+ 'host': 'localhost',
+ 'port': 3306,
+ 'database': 'parsoid',
+ 'user': 'parsoid',
+ 'password': 'parsoidpw',
+ 'debug': false,
+ 'fetches': 6,
+ 'tries': 6,
+ 'cutofftime': 600
+};
+
+// Settings file
+var settings;
+try {
+ settings = require( './server.settings.js' );
+} catch ( e ) {
+ settings = {};
+}
// Command line options
var argv = optimist.usage( 'Usage: $0 [connection parameters]' )
- .boolean( 'help' )
.options( 'help', {
+ 'boolean': true,
'default': false,
describe: "Show usage information."
} )
.options( 'h', {
alias: 'host',
- 'default': 'localhost',
describe: 'Hostname of the database server.'
} )
.options( 'P', {
alias: 'port',
- 'default': 3306,
describe: 'Port number to use for connection.'
} )
.options( 'D', {
alias: 'database',
- 'default': 'parsoid',
describe: 'Database to use.'
} )
.options( 'u', {
alias: 'user',
- 'default': 'parsoid',
- describe: 'User for login.'
+ describe: 'User for MySQL login.'
} )
.options( 'p', {
alias: 'password',
- 'default': 'parsoidpw',
describe: 'Password.'
} )
- .boolean( 'd' )
.options( 'd', {
alias: 'debug',
- 'default': false,
- describe: "Output MySQL debug."
+ 'boolean': true,
+ describe: "Output MySQL debug data."
} )
+ .options( 'f', {
+ alias: 'fetches',
+ describe: "Number of times to try fetching a page."
+ } )
+ .options( 't', {
+ alias: 'tries',
+ describe: "Number of times an article will be sent for testing
" +
+ "before it's considered an error."
+ } )
+ .options( 'c', {
+ alias: 'cutofftime',
+ describe: "Time in seconds to wait for a test result."
+ })
.argv;
if ( argv.help ) {
@@ -54,19 +78,30 @@
process.exit( 0 );
}
+var getOption = function( opt ) {
+ return argv[ opt ] || settings[ opt ] || defaults[ opt ];
+};
+
+var // The maximum number of tries per article
+ maxTries = getOption( 'tries' ),
+ // The maximum number of fetch retries per article
+ maxFetchRetries = getOption( 'fetches' ),
+ // The time to wait before considering a test has failed
+ cutOffTime = getOption( 'cutofftime' );
+
var mysql = require( 'mysql' );
var db = mysql.createConnection({
- host : argv.host,
- port : argv.port,
- database : argv.database,
- user : argv.user,
- password : argv.password,
+ host : getOption( 'host' ),
+ port : getOption( 'port' ),
+ database : getOption( 'database' ),
+ user : getOption( 'user' ),
+ password : getOption( 'password'),
multipleStatements : true,
- debug : argv.debug
+ debug : getOption( 'debug' )
} );
var queues = require( 'mysql-queues' );
-queues( db, argv.debug );
+queues( db, getOption( 'debug' ) );
// Try connecting to the database.
process.on( 'exit', function() {
@@ -409,7 +444,7 @@
//
// Hopefully, no page takes longer than 10 minutes to parse. :)
- claimPage( req.query.commit, new Date( Date.now() - ( 600 * 1000 ) ),
req, res );
+ claimPage( req.query.commit, new Date( Date.now() - ( cutOffTime * 1000
) ), req, res );
};
var statsScore = function(skipCount, failCount, errorCount) {
diff --git a/js/tests/server/server.settings.js.example
b/js/tests/server/server.settings.js.example
new file mode 100644
index 0000000..06294ee
--- /dev/null
+++ b/js/tests/server/server.settings.js.example
@@ -0,0 +1,41 @@
+/*
+ * This is a sample configuration file.
+ * Copy this file to server.settings.js and edit that file to fit your
+ * MySQL connection and other settings.
+ *
+ * You can also override these settings with command line options, run
+ * $ node server.js --help
+ * to view them.
+ */
+
+module.exports = {
+ // Hostname of the database server.
+ host: "localhost",
+
+ // Port number to use for connection.
+ port: 3306,
+
+ // Database to use.
+ database: "parsoid",
+
+ // User for MySQL login.
+ user: "parsoid",
+
+ // Password.
+ password: "parsoidpw",
+
+ // Output MySQL debug data.
+ debug: false,
+
+ // Number of times to try fetching a page.
+ fetches: 6,
+
+ // Number of times an article will be sent for testing before it's
+ // considered an error.
+ tries: 6,
+
+ // Time in seconds to wait for a test result. If a test takes longer
than
+ // this, it will be considered a crash error. Be careful not to set
this to
+ // less than what any page takes to parse.
+ cutofftime: 600
+};
--
To view, visit https://gerrit.wikimedia.org/r/76754
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If877269980931157ee2e94996edfa4e473a6f610
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: rt_testing
Gerrit-Owner: Marcoil <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits