All files / test/Ice/retry Client.js

91.2% Statements 83/91
42.85% Branches 3/7
100% Functions 2/2
91.2% Lines 83/91

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 921x 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(communicator, communicator2) {
        const out = this.getWriter();
        const retry1 = new Test.RetryPrx(communicator, `retry:${this.getTestEndpoint()}`);
        let retry2 = new Test.RetryPrx(communicator, `retry:${this.getTestEndpoint()}`);
        out.write("calling regular operation with first proxy... ");
        await retry1.op(false);
        out.writeLine("ok");
        out.write("calling operation to kill connection with second proxy... ");
        try {
            await retry2.op(true);
            test(false);
        }
        catch (ex) {
            if (TestHelper.isBrowser()) {
                test(ex instanceof Ice.SocketException, ex);
            }
            else {
                // Nodejs
                test(ex instanceof Ice.ConnectionLostException, ex);
            }
            out.writeLine("ok");
        }
        out.write("calling regular operation with first proxy again... ");
        await retry1.op(false);
        out.writeLine("ok");
        out.write("testing idempotent operation... ");
        const count = await retry1.opIdempotent(4);
        test(count === 4);
        out.writeLine("ok");
        out.write("testing non-idempotent operation... ");
        try {
            await retry1.opNotIdempotent();
            test(false);
        }
        catch (ex) {
            test(ex instanceof Ice.LocalException, ex);
        }
        out.writeLine("ok");
        out.write("testing invocation timeout and retries... ");
        retry2 = new Test.RetryPrx(communicator2, retry1.toString());
        retry2.ice_getConnection();
        try {
            await retry2.ice_invocationTimeout(500).opIdempotent(4);
            test(false);
        }
        catch (ex) {
            test(ex instanceof Ice.InvocationTimeoutException, ex);
        }
        await retry2.opIdempotent(-1);
        out.writeLine("ok");
        await retry1.shutdown();
    }
    async run(args) {
        let communicator = null;
        let communicator2 = null;
        try {
            let [properties] = this.createTestProperties(args);
            //
            // For this test, we want to disable retries.
            //
            properties.setProperty("Ice.RetryIntervals", "0 1 10 1");
            //
            // We don't want connection warnings because of the timeout
            //
            properties.setProperty("Ice.Warn.Connections", "0");
            [communicator] = this.initialize(properties);
            //
            // Configure a second communicator for the invocation timeout
            // + retry test, we need to configure a large retry interval
            // to avoid time-sensitive failures.
            //
            properties = communicator.getProperties().clone();
            properties.setProperty("Ice.RetryIntervals", "0 1 10000");
            [communicator2] = this.initialize(properties);
            await this.allTests(communicator, communicator2);
        }
        finally {
            if (communicator2) {
                await communicator2.destroy();
            }
            if (communicator) {
                await communicator.destroy();
            }
        }
    }
}