Skip to content

Commit bb17e13

Browse files
author
Alec Gibson
committed
Add a unit test for connecting to legacy clients
This change adds a "legacy" version of ShareDB as a development dependency so that we can unit test the new handshake logic against old clients.
1 parent f3ebed3 commit bb17e13

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"lolex": "^5.1.1",
1919
"mocha": "^6.2.2",
2020
"nyc": "^14.1.1",
21+
"sharedb-legacy": "npm:sharedb@=1.1.0",
2122
"sinon": "^7.5.0"
2223
},
2324
"scripts": {

test/client/connection.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var expect = require('chai').expect;
22
var Backend = require('../../lib/backend');
33
var Connection = require('../../lib/client/connection');
4+
var LegacyConnection = require('sharedb-legacy/lib/client').Connection;
5+
var StreamSocket = require('../../lib/stream-socket');
46

57
describe('client connection', function() {
68
beforeEach(function() {
@@ -217,6 +219,31 @@ describe('client connection', function() {
217219
});
218220
});
219221

222+
it('still connects to legacy clients, whose ID changes on reconnection', function(done) {
223+
var currentBackend = this.backend;
224+
var socket = new StreamSocket();
225+
var legacyClient = new LegacyConnection(socket);
226+
currentBackend.connect(legacyClient);
227+
228+
var doc = legacyClient.get('test', '123');
229+
doc.create({foo: 'bar'}, function(error) {
230+
if (error) return done(error);
231+
var initialId = legacyClient.id;
232+
expect(initialId).to.equal(legacyClient.agent.clientId);
233+
expect(legacyClient.agent.src).to.be.null;
234+
legacyClient.close();
235+
currentBackend.connect(legacyClient);
236+
doc.submitOp({p: ['baz'], oi: 'qux'}, function(error) {
237+
if (error) return done(error);
238+
var newId = legacyClient.id;
239+
expect(newId).not.to.equal(initialId);
240+
expect(newId).to.equal(legacyClient.agent.clientId);
241+
expect(legacyClient.agent.src).to.be.null;
242+
done();
243+
});
244+
});
245+
});
246+
220247
it('errors when submitting an op with a very large seq', function(done) {
221248
this.backend.connect(null, null, function(connection) {
222249
var doc = connection.get('test', '123');

0 commit comments

Comments
 (0)