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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | 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 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 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";
// Verify that the client idle check does not abort the connection while dispatching a request.
// The server idle timeout is set to 1 second, and the server idle check is disabled.
// The client idle timeout is also set to 1 second, with the idle check enabled.
// The client sleeps for 2 seconds while dispatching the request.
// The client continues processing heartbeats while dispatching the request, preventing the connection from being aborted.
async function testConnectionNotAbortedByIdleCheck(properties, helper) {
const output = helper.getWriter();
output.write("testing connection not aborted by idle check... ");
// The server has 1s idle timeout, and disabled idle check.
const proxyString = `test-bidir: ${helper.getTestEndpoint(4)}`;
const completedPromise = new Ice.Promise();
const TestI = class extends Test.DelayedTestIntf {
async sleep(msecs, _) {
await Ice.Promise.delay(msecs);
completedPromise.resolve();
}
};
// Create a new communicator with the desired properties.
properties = properties.clone();
properties.setProperty("Ice.Connection.Client.IdleTimeout", "1");
properties.setProperty("Ice.Connection.Client.EnableIdleCheck", "1");
properties.setProperty("Ice.Warn.Connections", "0");
helper.updateLogFileProperty(properties, "-idleTimeout=1s");
const initData = new Ice.InitializationData();
initData.properties = properties;
const communicator = new Ice.Communicator(initData);
try {
const adapter = await communicator.createObjectAdapter("");
const callback = Test.TestIntfPrx.uncheckedCast(adapter.add(new TestI(), Ice.stringToIdentity("test")));
const p = new Test.TestIntfBidirPrx(communicator, proxyString);
const connection = await p.ice_getConnection();
test(connection != null);
connection.setAdapter(adapter);
await p.ice_oneway().makeSleep(false, 2000, callback);
await completedPromise;
output.writeLine("ok");
}
finally {
await communicator.destroy();
}
}
// Verify that the client idle check aborts the connection while dispatching a request.
// The server idle timeout is misconfigured and set to 3 seconds, with the server idle check disabled.
// The client idle timeout is set to 1 second, with the idle check enabled.
// The client sleeps for 2 seconds while dispatching the request.
// The client will not receive a heartbeat in time while dispatching the request, causing the connection to be aborted.
async function testConnectionAbortedByIdleCheck(properties, helper) {
const output = helper.getWriter();
output.write("testing connection aborted by idle check... ");
// The server has 3s idle timeout, and disabled idle check.
const proxyString = `test-bidir: ${helper.getTestEndpoint(5)}`;
const completedPromise = new Ice.Promise();
const TestI = class extends Test.DelayedTestIntf {
async sleep(msecs, _) {
await Ice.Promise.delay(msecs);
completedPromise.resolve();
}
};
// Create a new communicator with the desired properties.
properties = properties.clone();
properties.setProperty("Ice.Connection.Client.IdleTimeout", "1");
properties.setProperty("Ice.Connection.Client.EnableIdleCheck", "1");
properties.setProperty("Ice.Warn.Connections", "0");
helper.updateLogFileProperty(properties, "-idleTimeout=0");
const initData = new Ice.InitializationData();
initData.properties = properties;
const communicator = new Ice.Communicator(initData);
try {
const adapter = await communicator.createObjectAdapter("");
const obj = adapter.add(new TestI(), Ice.stringToIdentity("test"));
const callback = Test.TestIntfPrx.uncheckedCast(obj);
const p = new Test.TestIntfBidirPrx(communicator, proxyString);
const connection = await p.ice_getConnection();
test(connection != null);
connection.setAdapter(adapter);
await p.ice_oneway().makeSleep(true, 2000, callback);
await completedPromise;
output.writeLine("ok");
}
finally {
await communicator.destroy();
}
}
// Verifies the behavior with the server idle check enabled or disabled when the client and the server have mismatched idle
// timeouts (here: 3s on the server side and 1s on the client side).
async function testServerWithEnableDisableIdleCheck(enabled, properties, helper) {
const output = helper.getWriter();
const enabledString = enabled ? "enabled" : "disabled";
output.write(`testing with server idle check ${enabledString}... `);
// The server has 3s idle timeout, and enabled idle check.
const proxyString3s = `test: ${helper.getTestEndpoint(2)}`;
// Create a new communicator with the desired properties.
properties = properties.clone();
properties.setProperty("Ice.Connection.Client.IdleTimeout", "1");
properties.setProperty("Ice.Connection.Client.EnableIdleCheck", enabled ? "1" : "0");
properties.setProperty("Ice.Warn.Connections", "0");
helper.updateLogFileProperty(properties, "-idleTimeout=1s");
const initData = new Ice.InitializationData();
initData.properties = properties;
const communicator = new Ice.Communicator(initData);
try {
const p = new Test.TestIntfPrx(communicator, proxyString3s);
const connection = await p.ice_getConnection();
test(connection != null);
try {
await p.sleep(2000); // the implementation in the server sleeps for 2,000ms
test(!enabled);
}
catch (ex) {
test(ex instanceof Ice.ConnectionAbortedException);
test(enabled);
}
output.writeLine("ok");
}
finally {
await communicator.destroy();
}
}
// Verifies the idle check is disabled when the idle timeout is set to 0.
async function testNoIdleTimeout(properties, helper) {
const output = helper.getWriter();
output.write(`testing connection with idle timeout set to 0... `);
const proxyStringNoIdleTimeout = `test: ${helper.getTestEndpoint(3)}`;
// Create a new communicator with the desired properties.
properties = properties.clone();
properties.setProperty("Ice.Connection.Client.IdleTimeout", "0");
helper.updateLogFileProperty(properties, "-idleTimeout=0");
const initData = new Ice.InitializationData();
initData.properties = properties;
const communicator = new Ice.Communicator(initData);
try {
const p = new Test.TestIntfPrx(communicator, proxyStringNoIdleTimeout);
const connection = await p.ice_getConnection();
test(connection != null);
await p.sleep(2000); // the implementation in the server sleeps for 2,000ms
await connection.close();
output.writeLine("ok");
}
finally {
await communicator.destroy();
}
}
export class Client extends TestHelper {
async allTests() {
const communicator = this.communicator();
await testConnectionAbortedByIdleCheck(communicator.getProperties(), this);
await testConnectionNotAbortedByIdleCheck(communicator.getProperties(), this);
await testServerWithEnableDisableIdleCheck(true, communicator.getProperties(), this);
await testServerWithEnableDisableIdleCheck(false, communicator.getProperties(), this);
await testNoIdleTimeout(communicator.getProperties(), this);
const p = new Test.TestIntfPrx(communicator, `test: ${this.getTestEndpoint(0)}`);
await p.shutdown();
}
async run(args) {
let communicator = null;
try {
const [properties] = this.createTestProperties(args);
properties.setProperty("Ice.Connection.Client.IdleTimeout", "1");
[communicator] = this.initialize(properties);
await this.allTests();
}
finally {
if (communicator) {
await communicator.destroy();
}
}
}
}
|