Subramanya Sastry has uploaded a new change for review. https://gerrit.wikimedia.org/r/314785
Change subject: Add --record and --replay options to parse.js ...................................................................... Add --record and --replay options to parse.js * --record will record http requests in nocks/$prefix/$title.js * --replay will look for the nock file there and use it to replay http requests * Useful for performance testing by eliminating network latencies and freezing wikitext, templates, etc. Change-Id: Iabe2860d7e2070e0daf3e5ce442d21d55a8f5590 --- M bin/parse.js M package.json 2 files changed, 51 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/85/314785/1 diff --git a/bin/parse.js b/bin/parse.js index ac81cb9..a735d3f 100755 --- a/bin/parse.js +++ b/bin/parse.js @@ -148,6 +148,16 @@ 'boolean': true, 'default': false, }, + 'record': { + description: 'Record http requests for later replay', + 'boolean': true, + 'default': false, + }, + 'replay': { + description: 'Replay recorded http requests for later replay', + 'boolean': true, + 'default': false, + }, 'useBatchAPI': { description: 'Turn on/off the API batching system', // Since I picked a null default (to let the default config setting be the default), @@ -385,12 +395,51 @@ parsoidConfig.defaultWiki = prefix ? prefix : parsoidConfig.reverseMwApiMap.get(domain); + var nock, dir, nocksFile; + if (argv.record || argv.replay) { + prefix = prefix || 'enwiki'; + dir = path.resolve(__dirname, '../nocks/'); + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } + dir = dir + '/' + prefix; + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } + nocksFile = dir + '/' + argv.page + '.js'; + } + + if (argv.record) { + nock = require('nock'); + nock.recorder.rec({dont_print: true}); + } else if (argv.replay) { + try { + require(nocksFile); + } catch (e) { + console.error('Exception ' + e + ' requiring ' + nocksFile); + console.error('Cannot replay!'); + return -1; + } + } + return parse(null, argv, parsoidConfig, prefix, domain).then(function(res) { var stdout = process.stdout; stdout.write(res.out); if (res.trailingNL && stdout.isTTY) { stdout.write('\n'); } + + if (argv.record) { + var nockCalls = nock.recorder.play(); + var stream = fs.createWriteStream(nocksFile); + stream.once('open', function() { + stream.write("var nock = require('nock');"); + for (var i = 0; i < nockCalls.length; i++) { + stream.write(nockCalls[i]); + } + stream.end(); + }); + } }).done(); }()); } diff --git a/package.json b/package.json index a82682b..26e929b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "mocha": "^2.5.3", "npm-shrinkwrap": "^200.5.1", "nsp": "^2.6.1", - "supertest": "^1.2.0" + "supertest": "^1.2.0", + "nock": "^8.0.0" }, "main": "lib/index.js", "bin": { -- To view, visit https://gerrit.wikimedia.org/r/314785 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iabe2860d7e2070e0daf3e5ce442d21d55a8f5590 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits