client.connect(endpointUrl, function (err) { should(err).eql(null); client.createSession(function (err, session) { should(err).eql(null); g_session = session; done(); }); });
function create_session(callback) { client.createSession(function(err,session){ if (!err) { sessions.push(session); } callback(err); }); }
// create session function (callback) { client.createSession(function (err, session) { if (!err) { the_session = session; the_session.timeout.should.eql(client.requestedSessionTimeout); } callback(err); }); },
function createClientAndSession(data,_inner_callback) { var client = new OPCUAClient({ connectionStrategy: fail_fast_connectionStrategy }); client.connectionStrategy.maxRetry.should.eql(fail_fast_connectionStrategy.maxRetry); client.on("start_reconnection", function (err) { if(doDebug) { console.log("start_reconnection".bgWhite.yellow,data.index);} throw Error("Expecting automatic reconnection to be disabled"); }); client.on("backoff", function (number, delay) { if(doDebug) { console.log("backoff".bgWhite.yellow,number,delay);} throw Error("Expecting automatic reconnection to be disabled"); }); clients.push(client); async.series([ function(callback) { client.connect(endpointUrl, function (err) { if (!err) { client._secureChannel.connectionStrategy.maxRetry.should.eql(fail_fast_connectionStrategy.maxRetry); client.createSession(function(err,session){ if (!err) { sessions.push(session); } callback(); }); } else { rejected_connections ++; // ignore err here callback(); } }); } ],_inner_callback); }
it("ZAA1 should be possible to create many sessions per connection", function (done) { const client = OPCUAClient.create({ connectionStrategy: fail_fast_connectionStrategy }); const sessions = []; function create_session(callback) { client.createSession(function (err, session) { if (!err) { sessions.push(session); } callback(err); }); } async.series([ function (callback) { client.connect(endpointUrl, (err) => { callback(); }); }, create_session, create_session, create_session, create_session, function (callback) { async.eachLimit(sessions, 1, function (session, callback) { session.close(callback); }, callback); }, function (callback) { client.disconnect(callback); } ], done); });
before(function (done) { server = new OPCUAServer({port: 2000, nodeset_filename: empty_nodeset_filename}); // we will connect to first server end point endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl; debugLog("endpointUrl", endpointUrl); opcua.is_valid_endpointUrl(endpointUrl).should.equal(true); client = new OPCUAClient(); server.start(function () { setImmediate(function () { client.connect(endpointUrl, function (err) { should(err).eql(null); client.createSession(function (err, session) { should(err).eql(null); g_session = session; done(); }); }); }); }); });
function (callback) { client.connect(endpointUrl, function (err) { callback(); }); },
function(callback) { client.disconnect(callback); }
function createClientAndSession(data, _inner_callback) { const client = OPCUAClient.create({ connectionStrategy: fail_fast_connectionStrategy }); client.name = "client" + counter; counter += 1; client.connectionStrategy.maxRetry.should.eql(fail_fast_connectionStrategy.maxRetry); client.on("start_reconnection", (err) => { if (doDebug) { debugLog(chalk.bgWhite.yellow("start_reconnection"), data.index); } throw Error("Expecting automatic reconnection to be disabled"); }); client.on("backoff", (number, delay) => { if (doDebug) { debugLog(chalk.bgWhite.yellow("backoff"), number, delay); } throw Error("Expecting automatic reconnection to be disabled"); }); clients.push(client); async.series([ function (callback) { setTimeout(callback,10); }, function (callback) { if (doDebug) { debugLog(chalk.bgWhite.yellow("about to start client"), client.name); } client.connect(endpointUrl, function (err) { if (!err) { if (doDebug) { debugLog(chalk.bgWhite.yellow("client"), client.name, " connected"); } client._secureChannel.connectionStrategy.maxRetry.should.eql(fail_fast_connectionStrategy.maxRetry); client.createSession(function (err, session) { if (!err) { sessions.push(session); } callback(); }); } else { if (doDebug) { debugLog("client ", client.name, " connection has been rejected"); } rejected_connections++; // ignore err here callback(); } }); } ], _inner_callback); }
it("server should discard session from abruptly disconnected client after the timeout has expired", function (done) { // ask for a very short session timeout client = new OPCUAClient({requestedSessionTimeout: 200}); var the_session; async.series([ // assert that server has 0 session function (callback) { server.currentSessionCount.should.eql(0); callback(); }, // connect function (callback) { client.connect(endpointUrl, function (err) { callback(err); }); }, // create session function (callback) { client.createSession(function (err, session) { if (!err) { the_session = session; the_session.timeout.should.eql(client.requestedSessionTimeout); } callback(err); }); }, // assert that server has 1 sessions function (callback) { server.currentSessionCount.should.eql(1); callback(); }, function (callback) { abrupty_disconnect_client(client, callback); }, // assert that server has 1 sessions function (callback) { server.currentSessionCount.should.eql(1); callback(); }, // wait for time out function (callback) { setTimeout(callback, 4000); }, // assert that server has no more session function (callback) { server.currentSessionCount.should.eql(0); callback(); }, function (callback) { client.disconnect(callback); } ], done); // client.disconnect(function(){ });
tokenRenewalCount: 0, receivedBytes: 0, sentBytes: 0, sentChunks: 0, receivedChunks: 0, backoffCount: 0, transactionCount: 0, }; const client = opcua.OPCUAClient.create({ endpoint_must_exist: false, securityMode: securityMode, securityPolicy: securityPolicy, //xx serverCertificate: serverCertificate, defaultSecureTokenLifetime: 40000, certificateFile: certificateFile, privateKeyFile: privateKeyFile, keepSessionAlive: true }); client.on("send_request", function () { data.transactionCount++; }); client.on("send_chunk", function (chunk) { data.sentBytes += chunk.length; data.sentChunks++; });