summaryrefslogtreecommitdiff
path: root/swift/test/Ice/operations/BatchOnewaysAMI.swift
blob: 85277b4ddd756e6eb95d6094615f40ff8a9015c2 (plain)
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
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import Darwin
import Ice
import PromiseKit
import TestCommon

func batchOnewaysAMI(_ helper: TestHelper, _ p: MyClassPrx) throws {
    func test(_ value: Bool, file: String = #file, line: Int = #line) throws {
        try helper.test(value, file: file, line: line)
    }

    let bs1 = ByteSeq(repeating: 0, count: 10 * 1024)
    let batch = p.ice_batchOneway()

    try firstly {
        batch.ice_flushBatchRequestsAsync()
    }.wait()

    for _ in 0 ..< 30 {
        _ = batch.opByteSOnewayAsync(bs1)
    }

    var count: Int32 = 0
    while count < 27 { // 3 * 9 requests auto-flushed.
        count += try p.opByteSOnewayCallCount()
        usleep(100)
    }

    let conn = try batch.ice_getConnection()
    if conn != nil {
        let batch1 = uncheckedCast(prx: p.ice_batchOneway(), type: MyClassPrx.self)
        let batch2 = uncheckedCast(prx: p.ice_batchOneway(), type: MyClassPrx.self)

        _ = batch1.ice_pingAsync()
        _ = batch2.ice_pingAsync()
        try batch1.ice_flushBatchRequestsAsync().wait()
        try batch1.ice_getConnection()!.close(Ice.ConnectionClose.GracefullyWithWait)
        _ = batch1.ice_pingAsync()
        _ = batch2.ice_pingAsync()

        _ = try batch1.ice_getConnection()
        _ = try batch2.ice_getConnection()

        _ = batch1.ice_pingAsync()
        try batch1.ice_getConnection()!.close(Ice.ConnectionClose.GracefullyWithWait)

        _ = batch1.ice_pingAsync()
        _ = batch2.ice_pingAsync()
    }

    let batch3 = batch.ice_identity(Ice.Identity(name: "invalid", category: ""))
    _ = batch3.ice_pingAsync()
    try batch3.ice_flushBatchRequestsAsync().wait()

    // Make sure that a bogus batch request doesn't cause troubles to other ones.
    _ = batch3.ice_pingAsync()
    _ = batch.ice_pingAsync()
    try batch.ice_flushBatchRequestsAsync().wait()
    _ = batch.ice_pingAsync()
}