-
-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to overide default transport timeout when creating client #…
- Loading branch information
1 parent
2a26a65
commit 1b97628
Showing
8 changed files
with
153 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
packages/node-opcua-end2end-test/test/end_to_end/test_e2e_1002.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import "should"; | ||
import * as sinon from "sinon"; | ||
import { ClientSecureChannelLayer, get_mini_nodeset_filename, OPCUAClient, OPCUAServer } from "node-opcua"; | ||
|
||
const port = 2128; | ||
|
||
async function startServer(): Promise<OPCUAServer> { | ||
// get IP of the machine | ||
const mini = get_mini_nodeset_filename(); | ||
|
||
const server = new OPCUAServer({ | ||
port, | ||
// nodeset_filename: [nodesets.standard], | ||
nodeset_filename: [mini] | ||
}); | ||
await server.initialize(); | ||
await server.start(); | ||
return server; | ||
} | ||
// tslint:disable-next-line:no-var-requires | ||
const describe = require("node-opcua-leak-detector").describeWithLeakDetector; | ||
describe("#1002 - ability to set transport timeout ", () => { | ||
let server: OPCUAServer; | ||
before(async () => { | ||
server = await startServer(); | ||
}); | ||
after(async () => { | ||
await server.shutdown(); | ||
server.dispose(); | ||
}); | ||
it("A- using default transport timeout", async () => { | ||
const endpointUrl = server.getEndpointUrl(); | ||
const client = OPCUAClient.create({}); | ||
const spyConnectionLost = sinon.spy(); | ||
const spyClose = sinon.spy(); | ||
const spyConnectionReestablished = sinon.spy(); | ||
client.on("connection_lost", spyConnectionLost); | ||
client.on("close", spyClose); | ||
client.on("connection_reestablished", spyConnectionReestablished); | ||
const actualTimeout = await client.withSessionAsync<number>(endpointUrl, async (session) => { | ||
const timeout = (client as any)._secureChannel!._transport.timeout; | ||
const socket = (client as any)._secureChannel!._transport._socket as NodeJS.Socket; | ||
socket.on("timeout", () => console.log("socket timeout")); | ||
return timeout; | ||
}); | ||
actualTimeout.should.eql(ClientSecureChannelLayer.defaultTransportTimeout); | ||
spyClose.callCount.should.eql(1); | ||
spyConnectionLost.callCount.should.eql(0); | ||
spyConnectionReestablished.callCount.should.eql(0); | ||
}); | ||
it("B- should be possible to set the transport timeout - no automatic reconnection", async () => { | ||
const endpointUrl = server.getEndpointUrl(); | ||
|
||
const transportTimeout = 1234; | ||
const client = OPCUAClient.create({ | ||
transportTimeout, | ||
connectionStrategy: { maxRetry: 0 } // we don't want automatic reconnection => maxRetry = 0 | ||
}); | ||
client.on("backoff", () => console.log("keep trying", endpointUrl)); | ||
client.on("connection_lost", () => console.log("connection lost")); | ||
client.on("connection_reestablished", () => console.log("connection_reestablished")); | ||
const spyConnectionLost = sinon.spy(); | ||
const spyClose = sinon.spy(); | ||
const spyConnectionReestablished = sinon.spy(); | ||
client.on("connection_lost", spyConnectionLost); | ||
client.on("close", spyClose); | ||
client.on("connection_reestablished", spyConnectionReestablished); | ||
|
||
const actualTimeout = await client.withSessionAsync(endpointUrl, async (session) => { | ||
const timeout = (client as any)._secureChannel!._transport.timeout; | ||
const socket = (client as any)._secureChannel!._transport._socket as NodeJS.Socket; | ||
socket.on("timeout", () => console.log("socket timeout")); | ||
|
||
console.log("timeout = ", timeout); | ||
console.log("connected"); | ||
await new Promise((resolve) => setTimeout(resolve, transportTimeout + 4000)); | ||
console.log("done"); | ||
|
||
return (timeout as number) || 0; | ||
}); | ||
actualTimeout.should.eql(transportTimeout); | ||
spyConnectionLost.callCount.should.eql(1); | ||
spyClose.callCount.should.eql(1); | ||
spyConnectionReestablished.callCount.should.eql(0); | ||
}); | ||
|
||
it("C- should be possible to set the transport timeout - with automatic reconnection", async () => { | ||
const endpointUrl = server.getEndpointUrl(); | ||
|
||
const transportTimeout = 1000; | ||
const client = OPCUAClient.create({ | ||
transportTimeout, | ||
connectionStrategy: { maxRetry: 1 } // we WANT automatic reconnection => maxRetry <> 1 | ||
}); | ||
client.on("backoff", () => console.log("keep trying", endpointUrl)); | ||
client.on("connection_lost", () => console.log("connection lost")); | ||
client.on("connection_reestablished", () => console.log("connection_reestablished")); | ||
const spyConnectionLost = sinon.spy(); | ||
const spyClose = sinon.spy(); | ||
const spyConnectionReestablished = sinon.spy(); | ||
client.on("connection_lost", spyConnectionLost); | ||
client.on("close", spyClose); | ||
client.on("connection_reestablished", spyConnectionReestablished); | ||
|
||
const actualTimeout = await client.withSessionAsync(endpointUrl, async (session) => { | ||
const timeout = (client as any)._secureChannel!._transport.timeout; | ||
const socket = (client as any)._secureChannel!._transport._socket as NodeJS.Socket; | ||
socket.on("timeout", () => console.log("socket timeout")); | ||
|
||
console.log("timeout = ", timeout); | ||
console.log("connected"); | ||
await new Promise((resolve) => setTimeout(resolve, transportTimeout + 6000)); | ||
console.log("done"); | ||
|
||
return (timeout as number) || 0; | ||
}); | ||
actualTimeout.should.eql(transportTimeout); | ||
spyConnectionLost.callCount.should.be.greaterThan(2); | ||
spyConnectionReestablished.callCount.should.be.greaterThan(2); | ||
spyClose.callCount.should.eql(1); | ||
spyConnectionReestablished.callCount.should.be.greaterThan(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters