All files / test/Ice/operations BatchOneways.js

97.22% Statements 70/72
87.5% Branches 7/8
100% Functions 1/1
97.22% Lines 70/72

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 731x 1x 1x 1x 1x 1x 1x 10240x 10240x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 30x 30x 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 11x 11x 1x 1x 1x     1x 1x 1x 1x  
// Copyright (c) ZeroC, Inc.
import { Ice } from "@zeroc/ice";
import { Test } from "./Test.js";
import { test } from "../../Common/TestHelper.js";
export async function batchOneways(prx, helper) {
    const bs1 = new Uint8Array(10 * 1024);
    for (let i = 0; i < bs1.length; ++i) {
        bs1[i] = 0;
    }
    const batch = Test.MyInterfacePrx.uncheckedCast(prx.ice_batchOneway());
    await batch.ice_flushBatchRequests();
    let r = batch.ice_flushBatchRequests();
    await r;
    test(r.isCompleted()); // Empty flush
    r = batch.ice_flushBatchRequests();
    await r;
    test(r.isSent()); // Empty flush
    r = batch.ice_flushBatchRequests();
    await r;
    test(r.isCompleted()); // Empty flush
    for (let i = 0; i < 30; ++i) {
        await batch.opByteSOneway(bs1);
    }
    let count = 0;
    while (count < 27) {
        // 3 * 9 requests auto-flushed.
        count += await prx.opByteSOnewayCallCount();
        await Ice.Promise.delay(10);
    }
    if (batch.ice_getConnection() !== null) {
        const batch1 = Test.MyInterfacePrx.uncheckedCast(prx.ice_batchOneway());
        const batch2 = Test.MyInterfacePrx.uncheckedCast(prx.ice_batchOneway());
        batch1.ice_ping();
        batch2.ice_ping();
        await batch1.ice_flushBatchRequests();
        await batch1.ice_getConnection().then((c) => c.close());
        batch1.ice_ping();
        batch2.ice_ping();
        await batch1.ice_getConnection();
        await batch2.ice_getConnection();
        batch1.ice_ping();
        await batch1.ice_getConnection().then((c) => c.close());
        batch1.ice_ping();
        batch2.ice_ping();
    }
    const identity = new Ice.Identity();
    identity.name = "invalid";
    const batch3 = batch.ice_identity(identity);
    batch3.ice_ping();
    await batch3.ice_flushBatchRequests();
    // Make sure that a bogus batch request doesn't cause troubles to other ones.
    batch3.ice_ping();
    batch.ice_ping();
    await batch.ice_flushBatchRequests();
    await batch.ice_ping();
    // Nothing listens on this endpoint.
    const unreachable = Test.MyInterfacePrx.uncheckedCast(new Test.MyInterfacePrx(prx.ice_getCommunicator(), `test:${helper.getTestEndpoint(1)}`).ice_batchOneway());
    // Filling the batch past Ice.BatchAutoFlushSize triggers an auto-flush that cannot connect. It fails silently:
    // the batched requests are lost, like any other oneway, and the failure is not reported to the caller that
    // happened to fill the batch.
    for (let i = 0; i < 11; ++i) {
        await unreachable.opByteSOneway(bs1);
    }
    try {
        // This flush fails the same way; by the time it does, the auto-flush above has settled too.
        await unreachable.ice_flushBatchRequests();
        test(false);
    }
    catch (ex) {
        test(ex instanceof Ice.LocalException, ex);
    }
}