Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | // Copyright (c) ZeroC, Inc.
import { Ice } from "@zeroc/ice";
import { Test } from "./Test.js";
import { TestHelper, test } from "../../Common/TestHelper.js";
export class Client extends TestHelper {
async allTests() {
const controller = new Test.ControllerPrx(this.communicator(), `controller:${this.getTestEndpoint(1)}`);
test(controller !== null);
try {
await this.allTestsWithController(controller);
}
catch (ex) {
// Ensure the adapter is not in the holding state when an unexpected exception occurs to prevent the test
// from hanging on exit in case a connection which disables timeouts is still opened.
controller.resumeAdapter();
throw ex;
}
}
async allTestsWithController(controller) {
const communicator = this.communicator();
const out = this.getWriter();
const timeout = new Test.TimeoutPrx(communicator, `timeout: ${this.getTestEndpoint()}`);
out.write("testing connect timeout... ");
{
await controller.holdAdapter(-1);
try {
await timeout.op(); // Expect ConnectTimeoutException.
test(false);
}
catch (ex) {
test(ex instanceof Ice.ConnectTimeoutException, ex);
}
controller.resumeAdapter();
await timeout.op(); // Ensure adapter is active.
}
{
const properties = communicator.getProperties().clone();
properties.setProperty("Ice.Connection.Client.ConnectTimeout", "-1");
const [communicator2, _] = this.initialize(properties);
const to = new Test.TimeoutPrx(communicator2, timeout.toString());
controller.holdAdapter(100);
try {
await to.op(); // Expect success.
}
catch (ex) {
test(false, ex);
}
finally {
await controller.resumeAdapter();
await communicator2.destroy();
}
}
out.writeLine("ok");
out.write("testing invocation timeout... ");
{
const connection = await timeout.ice_getConnection();
let to = timeout.ice_invocationTimeout(100);
test(connection == (await to.ice_getConnection()));
try {
await to.sleep(1000);
test(false);
}
catch (ex) {
test(ex instanceof Ice.InvocationTimeoutException, ex);
}
await timeout.ice_ping();
to = timeout.ice_invocationTimeout(1000);
test(connection === (await timeout.ice_getConnection()));
try {
await to.sleep(100);
}
catch (ex) {
test(false, ex);
}
}
out.writeLine("ok");
out.write("testing close timeout... ");
{
try {
const connection = await timeout.ice_getConnection();
await controller.holdAdapter(-1);
const closed = connection.close();
try {
connection.getInfo(); // getInfo() doesn't throw in the closing state
}
catch (ex) {
test(false, ex);
}
try {
await closed;
test(false);
}
catch (ex) {
test(ex instanceof Ice.CloseTimeoutException, ex);
}
try {
connection.getInfo();
}
catch (ex) {
test(ex instanceof Ice.CloseTimeoutException, ex);
}
}
finally {
await controller.resumeAdapter();
}
}
controller.shutdown();
out.writeLine("ok");
}
async run(args) {
let communicator = null;
try {
const [properties] = this.createTestProperties(args);
//
// For this test, we want to disable retries.
//
properties.setProperty("Ice.RetryIntervals", "-1");
properties.setProperty("Ice.Connection.Client.ConnectTimeout", "1");
properties.setProperty("Ice.Connection.Client.CloseTimeout", "1");
[communicator] = this.initialize(properties);
await this.allTests();
}
finally {
if (communicator) {
await communicator.destroy();
}
}
}
}
|