2023-03-03 11:42:20 +01:00
|
|
|
describe('Remote Procedure Call', function () {
|
|
|
|
|
|
|
|
before(() => {
|
|
|
|
return Edge.connect();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(() => {
|
|
|
|
Edge.disconnect();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call the remote echo() method and resolve the returned value', function () {
|
|
|
|
const foo = "bar";
|
|
|
|
|
|
|
|
return Edge.rpc('echo', { foo })
|
|
|
|
.then(result => {
|
|
|
|
console.log(result);
|
|
|
|
chai.assert.equal(result.foo, foo);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call the remote throwErrorFromClient() method and reject with an error', function () {
|
|
|
|
return Edge.rpc('throwErrorFromClient')
|
|
|
|
.catch(err => {
|
|
|
|
// Assert that it's an "internal" error
|
|
|
|
// See https://www.jsonrpc.org/specification#error_object
|
|
|
|
chai.assert.equal(err.code, -32603);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call an unregistered method and reject with an error', function () {
|
|
|
|
return Edge.rpc('unregisteredMethod')
|
|
|
|
.catch(err => {
|
|
|
|
// Assert that it's an "method not found" error
|
|
|
|
// See https://www.jsonrpc.org/specification#error_object
|
|
|
|
chai.assert.equal(err.code, -32601);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should call the add() method repetitively and keep count of the sent values', function () {
|
2023-04-13 11:02:24 +02:00
|
|
|
this.timeout(30000);
|
2023-03-03 11:42:20 +01:00
|
|
|
|
|
|
|
const values = [];
|
|
|
|
for (let i = 0; i <= 1000; i++) {
|
|
|
|
values.push((Math.random() * 1000 | 0));
|
|
|
|
}
|
|
|
|
return Edge.rpc('reset')
|
|
|
|
.then(() => {
|
|
|
|
return Promise.all(values.map(v => Edge.rpc("add", { value: v })));
|
|
|
|
})
|
|
|
|
.then(() => Edge.rpc('total'))
|
|
|
|
.then(remoteTotal => {
|
|
|
|
const localTotal = values.reduce((t, v) => t + v);
|
|
|
|
console.log("Remote total:", remoteTotal, "Local total:", localTotal);
|
|
|
|
chai.assert.equal(remoteTotal, localTotal)
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|