Skip to content

Commit 3ebf57d

Browse files
committed
Added automatic test workflow
1 parent 4df8074 commit 3ebf57d

7 files changed

Lines changed: 35 additions & 31 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ node test/testTimeSync.js
2929

3030
## Usage
3131

32-
The index.js file contains a simple logger built for the CDP Studio example case.
32+
The value.js file contains a simple logger built for the CDP Studio example case.
3333

3434
1. Set up and run the Logger in CDP Studio.
3535
(Refer to Help → Framework - Data Logging → How to Setup Logging in Automation System)
3636
https://cdpstudio.com/manual/cdp/cdplogger/cdplogger-configuration-example.html
3737

38-
2. Run the index.js file from the command line:
38+
2. Run the value.js file from the command line:
3939

4040
```bash
41-
node examples/index.js
41+
node examples/value.js
4242
```
4343

4444
For usage related to events run:

client.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class Client {
4040
if (!/^wss?:\/\//.test(url)) {
4141
url = `ws://${url}`;
4242
}
43+
// Same for ":17000"
44+
if (!/\:17000$/.test(url)) {
45+
url += ':17000';
46+
}
4347

4448
this.reqId = -1;
4549
this.autoReconnect = autoReconnect;
@@ -85,7 +89,7 @@ class Client {
8589
setEnableTimeSync(enable) {
8690
this.enableTimeSync = enable;
8791
if (!enable) {
88-
// Cancel any pending time sync requests so they wont update timeDiff later.
92+
// Cancel any pending time sync requests so they won't update timeDiff later.
8993
for (const key in this.storedPromises) {
9094
this.storedPromises[key].reject(new Error("Time sync disabled"));
9195
}
@@ -129,7 +133,7 @@ class Client {
129133
* larger data sets should be downloaded in patches.
130134
* - 4.0 (2024-01, CDP 4.12):
131135
* - Added NodeTag support to save custom tags for logged values (e.g. Unit or Description),
132-
* accessible via the clients API.
136+
* accessible via the client's API.
133137
* - Reduced network usage by having data responses only include changes instead of repeating unchanged values.
134138
* - Added support for string values and events.
135139
*
@@ -445,8 +449,7 @@ class Client {
445449
* This method checks if the tags for the specified sender are already cached. If so, it returns a
446450
* resolved promise with the cached tags. Otherwise, it initializes a pending promise for the sender,
447451
* sends a request for the sender's tags using `_sendEventSenderTagsRequest`, and returns a promise that
448-
* resolves when the tags are received. If no response is received within 5000 ms, it falls back to resolving
449-
* with an empty object.
452+
* resolves when the tags are received.
450453
*
451454
* @param {string} sender - The identifier of the event sender.
452455
* @returns {Promise<Object>} A promise that resolves with an object representing the tags for the sender.
@@ -867,7 +870,7 @@ class Client {
867870

868871
_reqDataPoints(nodeNames, startS, endS, noOfDataPoints, limit, requestId) {
869872
const _getDataPoints = (nodeIds) => {
870-
this._sendDataPointsRequest(nodeIds, startS, endS, requestId, limit, noOfDataPoints);
873+
this._sendDataPointsRequest(nodeIds, startS, endS, requestId, noOfDataPoints, limit);
871874
};
872875

873876
const rejectRequest = (error) => {
@@ -909,7 +912,7 @@ class Client {
909912
});
910913
}
911914

912-
_sendDataPointsRequest(nodeIds, startS, endS, requestId, limit, noOfDataPoints) {
915+
_sendDataPointsRequest(nodeIds, startS, endS, requestId, noOfDataPoints, limit) {
913916
const container = Container.create();
914917
container.messageType = Container.Type.eSignalDataRequest;
915918
container.signalDataRequest = {

examples/event.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
const cdplogger = require('../client');
55

6+
const { EventQueryFlags, MatchType } = cdplogger.Client;
7+
8+
69
async function main() {
7-
const client = new cdplogger.Client('ws://127.0.0.1:17000', false);
10+
const client = new cdplogger.Client('127.0.0.1', true);
811

912
try {
1013
console.log("Waiting for connection to establish...");
@@ -13,20 +16,17 @@ async function main() {
1316

1417
// Build the query with a limit and offset
1518
const query = {
16-
senderConditions: [
17-
{
18-
value: "CDPLoggerDemoApp.InvalidLicense",
19-
matchType: cdplogger.Client.MatchType.Exact
20-
}
21-
],
19+
senderConditions: [{
20+
value: "CDPLoggerDemoApp.InvalidLicense",
21+
matchType: MatchType.Exact
22+
}],
2223
dataConditions: {
23-
"Text": {
24-
value: "*", // Wildcard condition for Text field
25-
}
24+
Text: ["Invalid*"], //Wildcard is the default
25+
// Multiple data conditions can be specified
2626
},
27-
flags: cdplogger.Client.EventQueryFlags.NewestFirst | cdplogger.Client.EventQueryFlags.UseLogStampForTimeRange,
28-
limit: 10, // Request a maximum of 10 events
29-
offset: 0 // Starting at the beginning
27+
limit: 100,
28+
offset: 0,
29+
flags: EventQueryFlags.NewestFirst | EventQueryFlags.UseLogStampForTimeRange
3030
};
3131

3232
console.log("Counting matching events...");
File renamed without changes.

generated/containerPb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO Guide on how this file was generated
12
/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
23
"use strict";
34

test/client.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ describe('ClientTester', () => {
106106
setImmediate(() => {
107107
expect(client._sendTimeRequest).toHaveBeenCalledWith(1);
108108
expect(client._sendDataPointsRequest).toHaveBeenCalledWith(
109-
[0, 1],
110-
1530613239.0,
111-
1530613270.0,
112-
2, // The second call's requestId
113-
500, // limit
114-
0 // noOfDataPoints
109+
[0, 1], // nodeIds
110+
1530613239.0, // startS
111+
1530613270.0, // endS
112+
2, // requestId
113+
0, // noOfDataPoints
114+
500 // limit
115115
);
116116
done();
117117
});
@@ -198,7 +198,7 @@ describe('ClientTester', () => {
198198
client.reqId = 0;
199199
client.isOpen = true;
200200
client._sendDataPointsRequest = jest.fn();
201-
client.requestDataPoints(["Output", "CPULoad"], 1531313250.0, 1531461231.0, 0, 500)
201+
client.requestDataPoints(["Output", "CPULoad"], 1531313250.0, 1531461231.0, 500, 0)
202202
.then(dataPoints => {
203203
expect(dataPoints[0].timestamp).toBeCloseTo(1531313250.0);
204204
expect(dataPoints[0].value["Output"].min).toBeCloseTo(0.638855091434);
@@ -220,7 +220,7 @@ describe('ClientTester', () => {
220220
delete client.idToName[id];
221221
}
222222
}
223-
client.requestDataPoints(["Output", "CPULoad"], 1531313250.0, 1531461231.0, 0, 500)
223+
client.requestDataPoints(["Output", "CPULoad"], 1531313250.0, 1531461231.0, 500, 0)
224224
.catch(error => {
225225
expect(error).toBeInstanceOf(Error);
226226
expect(error.message).toMatch(/Output/);

test/testTimeSync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async function runTest() {
171171

172172
await runThrough(
173173
"requestDataPoints",
174-
() => client.requestDataPoints(["Output", "CPULoad"], 1531313250.0, 1531461231.0, 500),
174+
() => client.requestDataPoints(["Output", "CPULoad"], 1531313250.0, 1531461231.0, 0, 500),
175175
(timeSyncId, apiId) => {
176176
const timeResponse = {
177177
messageType: fakeData.Container.Type.eTimeResponse,

0 commit comments

Comments
 (0)