Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

flaky server test and hacked up implementation

  • Loading branch information...
commit 0ef1790173912b85f30b7e2147a790508e6c9ab5 1 parent c3ed120
@mbrevoort authored
Showing with 80 additions and 1 deletion.
  1. +17 −1 lib/seaport.js
  2. +63 −0 test/flaky_server.js
View
18 lib/seaport.js
@@ -245,12 +245,28 @@ Seaport.prototype.register = function (role, opts) {
Seaport.prototype.reinitialize = function () {
var self = this;
+ //console.error("REINIT+++\n\n", self.doc, '\n\n')
+ // delete this clients copies of records of any
+ // other services but itself. Not using self.doc.rm(row.id);
+ // because that would cause change events that would ripple
+ // through once reconnected. Clear out the history as well.
for (var id in self.doc.rows) {
if(self.doc.rows.hasOwnProperty(id)) {
var row = self.doc.rows[id];
- if (row.state._node !== self.doc.id) self.doc.rm(row.id);
+ if (row.state._node !== self.doc.id) {
+ delete self.services.rows[id]
+ self.services._array = self.services._array.filter(function (it) { return it.id !== id });
+ delete self.addresses.rows[id]
+ self.addresses._array = self.addresses._array.filter(function (it) { return it.id !== id });
+ delete self.doc.rows[id]
+ delete self.doc.hist[id]
+ // self.doc.rm(row.id);
+ }
}
}
+ //console.error("REINIT---\n\n", self.doc, '\n\n')
+ //console.error('!!!!!!\n\n', this.query(""), '\n\n!!!!')
+ //console.error(self.services.toJSON())
}
Seaport.matches = matches;
View
63 test/flaky_server.js
@@ -0,0 +1,63 @@
+var seaport = require('../');
+var test = require('tap').test;
+
+var destroyer = require('destroyer');
+
+test('flaky-server', function (t) {
+ t.plan(9);
+
+ var server0 = seaport.createServer();
+ var server1 = seaport.createServer();
+
+ var destroy0 = destroyer(server0);
+ var destroy1 = destroyer(server1);
+
+ server0.listen(0);
+ var port = server0.address().port;
+
+
+ var ports0 = seaport.connect(port);
+ var ports1 = seaport.connect(port);
+
+ var wport = ports0.register('woo');
+
+ var mport = ports1.register('moo');
+
+ setTimeout(function () {
+ t.equal(ports0.query('woo')[0].port, wport);
+ t.equal(server0.query('woo')[0].port, wport);
+ t.equal(ports0.query('moo')[0].port, mport);
+
+ // 1st kill the seaport server
+ destroy0();
+ }, 200);
+
+ setTimeout(function () {
+ t.equal(ports0.query('woo')[0].port, wport);
+
+ // Then kill ports1 with the moo registration
+ ports1.close();
+
+ // ports0 should still know about moo while still disconnected from
+ // a seaport server
+ t.equal(ports0.query('moo').length, 1);
+
+ setTimeout(function () {
+ // start a new seaport server on the same port as previous
+ server1.listen(port);
+
+ setTimeout(function () {
+ // server and client should know of woo, but not moo
+ t.equal(ports0.query('woo').length, 1);
+ t.equal(server1.query('woo').length, 1);
+ t.equal(ports0.query('moo').length, 0);
+ t.equal(server1.query('moo').length, 0);
+ }, 2000);
+ }, 500);
+ }, 300);
+
+ t.on('end', function () {
+ destroy1();
+ ports0.close();
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.