Refactor instance communication

Change Instance class to be a subclass of Link and refactor the
communication to and establisment of instances to use a virtual
connection between the slave and the instance.  This is simplifies the
implementation of plugin communication for instances.

Replace InstanceRequest with a forwardTo option to Request which does
the task of forwarding in a much cleaner way.
This commit is contained in:
Hornwitser committed 2019-12-13 21:57:05 +01:00
1 parent 9f24d200b7
commit 5d8fa4e4ce
7 files changed
+381 -265

No files matched your search

+18 -17
View File
@@ -18,6 +18,15 @@ describe("lib/link/messages", function() {
links: ['source-target'],
});
describe("constructor", function() {
it("should throw on invalid forwardTo", function() {
assert.throws(
() => new link.Request({ forwardTo: 'invalid'}),
new Error("Invalid forwardTo value invalid")
);
});
});
describe(".attach()", function() {
it("should attach validator to a source link", function() {
testRequest.attach(testSourceLink);
@@ -35,20 +44,6 @@ describe("lib/link/messages", function() {
testRequest.attach(testTargetLink, async (message) => handlerResult );
assert(testTargetLink._handlers.has('test_request'), "Handler was not set");
});
it("should throw on handler returning object with seq", async function() {
handlerResult = { seq: 3 };
testTargetLink._handlers.get('test_request')({ seq: 2 });
let result = await new Promise(resolve => {
testTargetLink.connector.send = (type, data) => resolve({ type, data });
});
assert.deepEqual(result, {
type: 'test_response',
data: {
error: "response contains reserved property 'seq'",
seq: 2,
},
});
});
it("should send result of calling the handler", async function() {
handlerResult = { test: "handler" };
testTargetLink._handlers.get('test_request')({ seq: 2 });
@@ -107,15 +102,21 @@ describe("lib/link/messages", function() {
});
});
describe("class InstanceRequest", function() {
});
describe("class Event", function() {
let testEvent = new link.Event({
type: 'test',
links: ['source-target'],
});
describe("constructor", function() {
it("should throw on invalid forwardTo", function() {
assert.throws(
() => new link.Event({ forwardTo: 'invalid'}),
new Error("Invalid forwardTo value invalid")
);
});
});
describe(".attach()", function() {
it("should throw if missing handler on target link", function() {
assert.throws(