@samtec-ash/virtuintestcomm
v0.9.8
Published
Virtuin Test Platform communication utilities for broadcasting, direct, etc communication over RabbitMQ.
Downloads
7
Readme
Virtuin Test Comm
Overview
Virtuin Test Comm. provides utilities for broadcasting, direct, etc communication over RabbitMQ.
The following classes are provided:
VirtuinTestPublisher: Used by active running test to update status and results to subscribers.
VirtuinTestSubscriber: Used by any process wanting to receive test status/result updates.
VirtuinTestViewClient: Used by test view (e.g. web-server) to send requests to test view server.
VirtuinTestViewServer: Used primarily by active test to listen for view requests.
VirtuinTestDispatcher: Used by Virtuin GUI to dispatch tests to a test environment server.
VirtuinTestHandler: Used within test environment to handle receiving test start/stop/status/clear requests.
Not recommended to be used alone. Instead use VirtuinTestServer.
Build
yarn run prepublish
Installation
yarn add @samtec-ash/virtuintestcomm
Examples
VirtuinTestPublisher
import {
VirtuinTestPublisher
} from '@samtec-hub/virtuintestcomm';
publisher = new VirtuinTestPublisher(
'DebugStation',
'DebugTest',
'DebugUUID'
);
await publisher.open('localhost');
publisher.updateStatus(
state='STARTING',
progress=0
);
await publisher.publish(
message='Just warming up.',
error=undefined,
customDict={a=1}
);
publisher.updateStatus(
state='FINISHED',
progress=100
);
await publisher.publish(
message='All done.',
error=undefined,
results=[{type='scalar', name='Temp', unit='C', value='28'}],
customDict={a=2}
);
await publisher.close();
VirtuinTestSubscriber
import {
VirtuinTestSubscriber
} from '@samtec-hub/virtuintestcomm';
subscriber = new VirtuinTestSubscriber('DebugStation');
await subscriber.open('localhost');
let subscribeTag;
const subscribeCB = async (err, data) => {
if (err) {
console.log(`Received error ${err}`);
} else if (data) {
if (data.state === 'STARTED') {
console.log('Test started');
} else if (data.progress === 100 || data.state === 'FINISHED') {
console.log('Test finished');
await subscriber.unsubscribe(subscribeTag);
await subscriber.close();
}
}
};
subscribeTag = await subscriber.subscribe(subscribeCB);
VirtuinTestViewServer
import {
VirtuinTestViewServer
} from '@samtec-hub/virtuintestcomm';
viewServer = new VirtuinTestViewServer('DebugStation', 'DebugTest');
await viewServer.open('localhost');
let listenTag;
const listenCB = async (err, data) => {
if (err) {
console.log(`Received error ${err}`);
} else if (data) {
if (typeof data.operation === 'string') {
switch(data.operation.toUpperCase()) {
case 'FOO': {
console.log('Doing FOO');
return { success: true, operation: 'FOO' };
}
case 'BAR': {
console.log('Doing BAR');
return { success: true, operation: 'BAR' };
}
case 'EXIT': {
setTimeout(() => { viewServer.close(); }, 500);
return { success: true, operation: 'EXIT' };
}
default: {
console.log('Operation unknown');
return { success: false };
}
}
}
}
};
listenTag = await viewServer.listen(listenCB);
VirtuinTestViewClient
import {
VirtuinTestViewClient
} from '@samtec-hub/virtuintestcomm';
viewClient = new VirtuinTestViewClient('DebugStation', 'DebugTest');
await viewClient.open('localhost');
viewClient.write({ operation: 'FOO' });
viewClient.close();