function Int64_add(a,b)
{
    assert(a[0]>=0 && a[0]<=0xFFFFFFFF);
    assert(a[1]>=0 && a[1]<=0xFFFFFFFF);
    const low = (a[1] + b[1] ) & 0xFFFFFFFF;
    let carry = 0;
    if (low< a[1] || low <b[1]) {
        carry = 1;
    }
    const high = a[0] + b[0] +carry ;
    return [high,low]
}
function Int64_mul2(a)
{
    assert(a[0]>=0 && a[0]<=0xFFFFFFFF);
    assert(a[1]>=0 && a[1]<=0xFFFFFFFF);
    const low = (a[1] << 1) & 0xFFFFFFFF;
    let carry = 0;
    if (low< a[1] ) {
        carry = 1;
    }
    const high = (a[0]<<1) +carry ;
    return [high,low]
}
 const spyOnServerWrite = sinon.spy(function (socket, data) {
     assert(data);
     // received Fake HEL Message
     // send Fake ACK response
     const messageChunk = packTcpMessage("ACK", fakeAcknowledgeMessage);
     socket.write(messageChunk);
 });
 client.performMessageTransaction(registerServerRequest, function (err, response) {
     if (!err) {
         // RegisterServerResponse
         assert(response instanceof opcua.RegisterServerResponse);
     }
     externalFunc(err, response);
     callback();
 });
 transport.connect(url, function (err) {
     if (err) {
         console.log(chalk.bgWhite.red(" err = "), err.message);
     }
     assert(!err);
     const buf = transport.createChunk("MSG", "F", message1.length);
     message1.copy(buf, transport.headerSize, 0, message1.length);
     transport.write(buf);
 });
 transport.disconnect(function (err) {
     if (err) {
         console.log(chalk.bgWhite.red(" err = "), err.message);
     }
     assert(!err);
     setImmediate(function () {
         server_confirms_that_server_socket_has_been_closed.should.equal(true);
         transport_confirms_that_close_event_has_been_processed.should.equal(true);
         done(err);
     });
 });
 const spyOnServerWrite = sinon.spy(function (socket, data) {
     debugLog(chalk.cyan.bold("\ncounter = "), counter);
     debugLog(chalk.yellow.bold(hexDump(data)));
     if (counter === 1) {
         // HEL/ACK transaction
         const messageChunk = packTcpMessage("ACK", fakeAcknowledgeMessage);
         counter += 1;
         socket.write(messageChunk);
         return;
     }
     assert(false, "unexpected data received");
 });
exports.makeEndPoint = function () {

    var data = {
        endpointUrl: "toto",

        server: {

            applicationUri: "OPCUA  node-js",
            productUri: "some product uri",
            applicationName: {text: "Localised application name"},
            applicationType: ApplicationType.ClientAndServer,
            gatewayServerUri: "gatewayServerUri",
            discoveryProfileUri: "discoveryProfileUri",
            discoveryUrls: [
                "discoveryUrls1",
                "discoveryUrls2",
                "discoveryUrls3",
                "discoveryUrls4",
                "discoveryUrls5"
            ]
        },

        serverCertificate: Buffer.alloc(256),

        securityMode: MessageSecurityMode.None,

        securityPolicyUri: "http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15",
        userIdentityTokens: [
            {
                policyId: "policyId",
                tokenType: UserTokenType.Anonymous,
                issuedTokenType: "issuedTokenType",
                issuerEndpointUrl: "qdqsdq",
                securityPolicyUri: "String"
            }
        ],
        transportProfileUri: "",
        securityLevel: 36
    };
    var value = new EndpointDescription(data);
    assert(value.server);
    return value;
};
        const spyOnServerWrite = sinon.spy(function (socket, data) {

            debugLog(chalk.cyan.bold("\ncounter = "), counter);
            debugLog(chalk.yellow.bold(hexDump(data)));
            if (counter === 1) {
                // HEL/ACK transaction
                const messageChunk = packTcpMessage("ACK", fakeAcknowledgeMessage);
                counter += 1;
                socket.write(messageChunk);

                setTimeout(function () {
                    debugLog(" Aborting server ");
                    socket.end(); // close after 10 ms
                }, 10);

            } else if (counter === 2) {
                //
            } else {
                assert(false, "unexpected data received");
            }
        });
 transport.init(fakeSocket.server, function (err) {
     assert(err);
     err.message.should.match(/BadProtocolVersionUnsupported/);
 });
 transport.init(fakeSocket.server, function (err) {
     assert(!err);
 });
 transport.init(fakeSocket.server, function (err) {
     assert(err);
     err.message.should.match(/Expecting \'HEL\' message/);
 });

const should = require("should");
const assert = require("node-opcua-assert").assert;
const async = require("async");
const _ = require("underscore");

const opcua = require("node-opcua");

const OPCUAServer = opcua.OPCUAServer;
const OPCUAClient = opcua.OPCUAClient;
const BrowseDirection = opcua.BrowseDirection;
const makeBrowsePath = opcua.makeBrowsePath;

assert(_.isFunction(makeBrowsePath));

const port = 2000;


const perform_operation_on_client_session = require("../../test_helpers/perform_operation_on_client_session").perform_operation_on_client_session;

const describe = require("node-opcua-leak-detector").describeWithLeakDetector;

describe("testing server with low maxNodesPerRead and maxNodesPerBrowse", function () {


    this.timeout(Math.max(this._timeout,10000));

    let server;

    let client;
 transport.connect(url, function (err) {
     assert(!err);
 });
 function makeError(statusCode) {
     assert(statusCode instanceof StatusCode);
     return new TCPErrorMessage({statusCode: statusCode, reason: statusCode.description});
 }