Commit 9d42dcde authored by Tom Jorquera's avatar Tom Jorquera
Browse files

Client now notifies server when ending

Server now exposes a callback for the client to notifies it when finished. This
allows the server to clean up the registry.

Careful, this introduces #65 when debugging.
parent 09f1992b
Pipeline #4541 passed with stage
in 58 seconds
...@@ -203,6 +203,12 @@ robot = { ...@@ -203,6 +203,12 @@ robot = {
robot.isDisconnected = true; robot.isDisconnected = true;
robotController.disconnect(); robotController.disconnect();
robot.clearConnection(); robot.clearConnection();
robot.notifyEndToServer();
},
// This function will be overridden by a server callback
notifyEndToServer: () => {
console.error('`notifyEndToServer`: Server has not registered a callback!');
} }
}; };
......
...@@ -35,6 +35,29 @@ const create = (runner, modules, config) => { ...@@ -35,6 +35,29 @@ const create = (runner, modules, config) => {
config.visio.url, config.visio.url,
room, room,
config.client); config.client);
// Add callback for client to inform when it leaves the room
controller.registry[room]
.timeouts('script', 2147483000) // We need big timeouts here (here ~600h)
.executeAsync(done => {
// Note that this code is executed in the selenium-driven browser
/* eslint-disable no-undef */
robot.notifyEndToServer = () => {
done('finished');
console.log('notified server I finished');
};
/* eslint-enable */
}).then(() => {
delete controller.registry[room];
console.log('client for room', room, 'finished');
}).catch(err => {
console.log('got error', err);
// Careful, there is a bug here with chomedriver; if we open the
// console of the selenium-driven browser, an exception is thrown.
// This means that this part may break in dev (but not in prod).
// See issue #65 for more details.
});
return controller.registry[room]; return controller.registry[room];
}, },
......
...@@ -25,11 +25,27 @@ const {create} = require('./controller.js'); ...@@ -25,11 +25,27 @@ const {create} = require('./controller.js');
// Here are some needed mocks // Here are some needed mocks
const functionRunnerMock = { const functionRunnerMock = {
execute() {
return { callbacks: [],
catch() {
return functionRunnerMock;
},
end() { end() {
} return functionRunnerMock;
}; },
execute() {
return functionRunnerMock;
},
executeAsync() {
return functionRunnerMock;
},
timeouts() {
return functionRunnerMock;
},
then(callback) {
functionRunnerMock.callbacks.push(callback);
return functionRunnerMock;
} }
}; };
...@@ -49,6 +65,7 @@ let controller; ...@@ -49,6 +65,7 @@ let controller;
describe('controller', () => { describe('controller', () => {
beforeEach(() => { beforeEach(() => {
controller = create(runnerMock, [], configMock); controller = create(runnerMock, [], configMock);
functionRunnerMock.callbacks = [];
}); });
test('should allow to create a client to a new room', () => { test('should allow to create a client to a new room', () => {
...@@ -84,4 +101,16 @@ describe('controller', () => { ...@@ -84,4 +101,16 @@ describe('controller', () => {
controller.forceDisconnect('test1'); controller.forceDisconnect('test1');
expect(controller.registry).toHaveProperty('test2', client2); expect(controller.registry).toHaveProperty('test2', client2);
}); });
test('should have registered a finish callback to the client', () => {
controller.client('test');
expect(functionRunnerMock.callbacks.length).toBe(1);
});
test('should clean registry on client finish callback', () => {
controller.client('test');
expect(controller.registry).toHaveProperty('test');
functionRunnerMock.callbacks[0]();
expect(controller.registry).not.toHaveProperty('test');
});
}); });
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment