Skip to content

Commit

Permalink
fix monitored item sample and object comparaison
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed May 26, 2020
1 parent b3bd8ae commit 835759f
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 78 deletions.
3 changes: 1 addition & 2 deletions packages/node-opcua-address-space/package.json
Expand Up @@ -46,7 +46,6 @@
"node-opcua-utils": "^2.6.0-alpha.1",
"node-opcua-variant": "^2.6.0-alpha.1",
"node-opcua-xml2json": "^2.6.0-alpha.1",
"object.values": "^1.1.1",
"pretty-error": "^2.1.1",
"set-prototype-of": "^1.0.0",
"thenify": "^3.3.0",
Expand Down Expand Up @@ -85,4 +84,4 @@
],
"homepage": "http://node-opcua.github.io/",
"gitHead": "07dcdd8e8c7f2b55544c6e23023093e35674829c"
}
}
2 changes: 0 additions & 2 deletions packages/node-opcua-address-space/src/base_node.ts
Expand Up @@ -65,8 +65,6 @@ import { MinimalistAddressSpace, Reference } from "./reference";
// tslint:disable:no-bitwise
// tslint:disable:no-console

require("object.values");

const doDebug = false;

function defaultBrowseFilterFunc(context?: SessionContext): boolean {
Expand Down
1 change: 0 additions & 1 deletion packages/node-opcua-address-space/src/ua_variable.ts
Expand Up @@ -617,7 +617,6 @@ export class UAVariable extends BaseNode implements UAVariablePublic {
context = SessionContext.defaultContext;
}

console.log("xyxy DataValue = ", dataValue.toString());
if (!dataValue.sourceTimestamp) {


Expand Down
Expand Up @@ -112,8 +112,8 @@ describe("AZA1- testing Client-Server subscription use case, on a fake server ex
try {

const itemToMonitor = {
attributeId: AttributeIds.Value,
nodeId,
attributeId: AttributeIds.Value
};
const parameters: MonitoringParametersOptions = {
queueSize: 10,
Expand Down
Expand Up @@ -28,7 +28,7 @@ const perform_operation_on_monitoredItem = require("../../test_helpers/perform_o

const Subscription = require("node-opcua-server").Subscription;

const doDebug = true;
const doDebug = false;
const f = require("../../test_helpers/display_function_name").f.bind(null, true);

function trace_console_log() {
Expand Down Expand Up @@ -1126,6 +1126,7 @@ module.exports = function(test) {
// - The second Publish contains a DataChangeNotification with a value.statusCode matching
// the written value (and value.value matching the value before the write).
// - The third Publish contains no DataChangeNotifications.
// (Did not expect a dataChange since the values written were the same, i.e. unchanged.)
perform_operation_on_subscription(client, endpointUrl, function(session, subscription, callback) {

const notificationMessageSpy = new sinon.spy();
Expand All @@ -1135,6 +1136,7 @@ module.exports = function(test) {
});

const monitoredItemOnChangedSpy = new sinon.spy();
const subscription_raw_notificiationSpy = new sinon.spy();

subscription.publishingInterval.should.eql(100);

Expand Down Expand Up @@ -1166,6 +1168,8 @@ module.exports = function(test) {
});

monitoredItem.on("changed", monitoredItemOnChangedSpy);

subscription.on("raw_notification", subscription_raw_notificiationSpy);
}


Expand Down Expand Up @@ -1214,24 +1218,25 @@ module.exports = function(test) {
create_monitored_item.bind(null),
wait.bind(null, 300),

// - Write a status code to the Value attribute (don’t change the value of the Value attribute).
write.bind(null, 1, StatusCodes.GoodWithOverflowBit),
wait.bind(null, 300),

// - Write the existing value and status code to the Value attribute.
write.bind(null, 1, StatusCodes.GoodWithOverflowBit),
wait.bind(null, 300),

function(callback) {
// wait until next notification received;
const lambda = (response) => {

console.log("response: ", response.constructor.name)
console.log("response: ", response.constructor.name, "notificationData.length", response.notificationMessage.notificationData.length);
if (response.constructor.name === "PublishResponse") {

client.removeListener("receive_response", lambda);
// console.log(" xxxx ", response.toString());

if (response.notificationMessage.notificationData.length !== 0) {
return callback(new Errro("Test has failed because PublishResponse has a unexpected notification data"))
return callback(new Error("Test has failed because PublishResponse has a unexpected notification data"))
}
callback();
}
Expand All @@ -1241,16 +1246,29 @@ module.exports = function(test) {
//xx wait.bind(null, subscription.publishingInterval * subscription.maxKeepAliveCount + 500),
function(callback) {

monitoredItemOnChangedSpy.callCount.should.eql(2);
monitoredItemOnChangedSpy.getCall(0).args[0].statusCode.should.eql(StatusCodes.Good);
monitoredItemOnChangedSpy.getCall(1).args[0].statusCode.should.eql(StatusCodes.GoodWithOverflowBit);

callback();
try {
if (doDebug) {
console.log("subscription_raw_notificiationSpy = ", subscription_raw_notificiationSpy.callCount);
console.log("monitoredItemOnChangedSpy = ", monitoredItemOnChangedSpy.callCount);
for (let i = 0; i < monitoredItemOnChangedSpy.callCount; i++) {
console.log(" ", monitoredItemOnChangedSpy.getCall(i).args[0].statusCode.toString());
}
}
monitoredItemOnChangedSpy.callCount.should.eql(2);
monitoredItemOnChangedSpy.getCall(0).args[0].statusCode.should.eql(StatusCodes.Good);
monitoredItemOnChangedSpy.getCall(1).args[0].statusCode.should.eql(StatusCodes.GoodWithOverflowBit);
callback();
} catch (err) {
console.log(err);
callback(err);
}

}
], callback);

}, done);
}, (err) => {
done(err);
});

});

Expand Down
Expand Up @@ -13,31 +13,39 @@
- * compare the published NotificationMessage to the republished NotificationMessage (should equal).
*/

const assert = require("node-opcua-assert").assert;
const async = require("async");
const { assert } = require("node-opcua-assert");
const should = require("should");
const sinon = require("sinon");
const opcua = require("node-opcua");
const chalk = require("chalk");

const OPCUAClient = opcua.OPCUAClient;
const {
OPCUAClient,
ClientSubscription
} = opcua;

const doDebug = false;

const {
perform_operation_on_subscription_async
} = require("../../test_helpers/perform_operation_on_client_session");

async function f(func) {
await async function() {
debugLog(" * " + func.name.replace(/_/g, " ").replace(/(given|when|then)/, chalk.green("**$1**")));
await func();
debugLog(" ! " + func.name.replace(/_/g, " ").replace(/(given|when|then)/, chalk.green("**$1**")));

}();
function f(func) {
const fct = async function(...args) {
if (doDebug) {
console.log(" * " + func.name.replace(/_/g, " ").replace(/(given|when|then)/, chalk.green("**$1**")));
}
await func.apply(null, args);
if (doDebug) {
console.log(" ! " + func.name.replace(/_/g, " ").replace(/(given|when|then)/, chalk.green("**$1**")));
}
}
return fct;
}
module.exports = function(test) {

describe("Testing ctt ", function() {

const ClientSubscription = opcua.ClientSubscription;
let subscription = null;

const nodeId = "ns=2;s=Scalar_Static_Int32";
Expand Down Expand Up @@ -153,7 +161,6 @@ module.exports = function(test) {
const response = await session.republish(request);
//xx console.log(" xx = ",index,request.toString());
//xx console.log(" xx = ",index,response.toString());
should.not.exist(err);
response.notificationMessage.notificationData[0].monitoredItems[0].should.eql(expected_values[index]);
}

Expand Down Expand Up @@ -189,9 +196,9 @@ module.exports = function(test) {
sequenceNumbers = [seqNumber1 + 1, seqNumber1 + 2, seqNumber1 + 3];
//xx console.log(expected_values, sequenceNumbers);

f(verify_republish)(session, 0);
f(verify_republish)(session, 1);
f(verify_republish)(session, 2);
await f(verify_republish)(session, 0);
await f(verify_republish)(session, 1);
await f(verify_republish)(session, 2);

});
});
Expand Down

0 comments on commit 835759f

Please sign in to comment.