jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/350970 )
Change subject: rebaser: Add script to convert a log file to a test case
......................................................................
rebaser: Add script to convert a log file to a test case
Change-Id: I0226bd5f3ed1323abd4de51e0c650553b4505333
---
A rebaser/logToTestCase.js
M tests/dm/ve.dm.RebaseServer.test.js
2 files changed, 99 insertions(+), 2 deletions(-)
Approvals:
jenkins-bot: Verified
Jforrester: Looks good to me, approved
diff --git a/rebaser/logToTestCase.js b/rebaser/logToTestCase.js
new file mode 100644
index 0000000..24d4b4b
--- /dev/null
+++ b/rebaser/logToTestCase.js
@@ -0,0 +1,93 @@
+/* eslint-disable no-console */
+
+var ve = require( '../dist/ve-rebaser.js' ),
+ fs = require( 'fs' );
+
+/**
+ * Parse log file contents.
+ *
+ * @param {string} log Newline-separated list of JSON objects
+ * @return {Object[]} Array of parsed objects
+ */
+function parseLog( log ) {
+ var i,
+ result = [],
+ lines = log.split( '\n' );
+ for ( i = 0; i < lines.length; i++ ) {
+ if ( lines[ i ] === '' ) {
+ continue;
+ }
+ try {
+ result.push( JSON.parse( lines[ i ] ) );
+ } catch ( e ) {
+ console.warn( e, lines[ i ] );
+ }
+ }
+ return result;
+}
+
+function toTestCase( parsedLog ) {
+ var i, type, author, clientId, changes, unsent, newChanges,
+ clients = [],
+ ops = [],
+ clientStates = {};
+ for ( i = 0; i < parsedLog.length; i++ ) {
+ type = parsedLog[ i ].type;
+ author = parsedLog[ i ].author;
+ clientId = parsedLog[ i ].clientId;
+ if ( type === 'newClient' ) {
+ clients.push( author );
+ clientStates[ author ] = {
+ unsent: 0,
+ submitting: false
+ };
+ } else if ( type === 'applyChange' ) {
+ if ( clientStates[ author ].submitting ) {
+ ops.push( [ author, 'deliver' ] );
+ clientStates[ author ].submitting = false;
+ }
+ } else if ( type === 'acceptChange' ) {
+ changes = ve.dm.Change.static.deserialize( parsedLog[ i
].change, null, true );
+ unsent = ve.dm.Change.static.deserialize( parsedLog[ i
].unsent, null, true );
+ newChanges = unsent.mostRecent( unsent.start +
clientStates[ clientId ].unsent );
+ // HACK: Deliberately using .getLength() > 0 instead of
.isEmpty() to ignore selection-only changes
+ if ( newChanges.getLength() > 0 ) {
+ ops.push( [ clientId, 'apply',
newChanges.serialize( true ) ] );
+ clientStates[ clientId ].unsent =
unsent.getLength();
+ }
+
+ if ( changes.getLength() > 0 ) {
+ ops.push( [ clientId, 'receive' ] );
+ }
+ } else if ( type === 'submitChange' ) {
+ changes = ve.dm.Change.static.deserialize( parsedLog[ i
].change, null, true );
+ newChanges = changes.mostRecent( changes.start +
clientStates[ clientId ].unsent );
+ if ( newChanges.getLength() > 0 ) {
+ ops.push( [ clientId, 'apply',
newChanges.serialize( true ) ] );
+ }
+
+ if ( clientStates[ clientId ].unsent +
newChanges.getLength() > 0 ) {
+ ops.push( [ clientId, 'submit' ] );
+ clientStates[ clientId ].unsent = 0;
+ clientStates[ clientId ].submitting = true;
+ }
+ }
+ }
+ return {
+ initialData: [],
+ clients: clients,
+ ops: ops
+ };
+}
+
+fs.readFile( process.argv[ 2 ], { encoding: 'utf8' }, function ( err, data ) {
+ var parsed = parseLog( data ),
+ testCase = toTestCase( parsed );
+ process.stdout.write( JSON.stringify( testCase ) );
+} );
+
+// acceptChange
+// submitChange
+// applyChange
+// newClient
+// disconnect
diff --git a/tests/dm/ve.dm.RebaseServer.test.js
b/tests/dm/ve.dm.RebaseServer.test.js
index fae3933..3c62c88 100644
--- a/tests/dm/ve.dm.RebaseServer.test.js
+++ b/tests/dm/ve.dm.RebaseServer.test.js
@@ -233,8 +233,12 @@
client = clients[ op[ 0 ] ];
action = op[ 1 ];
if ( action === 'apply' ) {
- txs = op[ 2 ].map( makeTransaction.bind( null,
client.doc ) );
- client.applyTransactions( txs );
+ if ( Array.isArray( op[ 2 ] ) ) {
+ txs = op[ 2 ].map(
makeTransaction.bind( null, client.doc ) );
+ client.applyTransactions( txs );
+ } else {
+ client.applyChange(
ve.dm.Change.static.deserialize( op[ 2 ] ) );
+ }
} else if ( action === 'assertHist' ) {
assert.equal( client.getHistorySummary(), op[ 2
], cases[ i ].name + ': ' + ( op[ 3 ] || j ) );
} else if ( action === 'submit' ) {
--
To view, visit https://gerrit.wikimedia.org/r/350970
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0226bd5f3ed1323abd4de51e0c650553b4505333
Gerrit-PatchSet: 3
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits