Skip to content

Commit

Permalink
Fix Ice/timeout by making sure controller is connected (#3215)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Dec 2, 2024
1 parent ea9a2b8 commit 41307f9
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 68 deletions.
5 changes: 4 additions & 1 deletion cpp/test/Ice/timeout/AllTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace
// Establish connection with the given proxy (which might have a timeout
// set and might sporadically fail on connection establishment if it's
// too slow). The loop ensures that the connection is established by retrying
// in case we can a ConnectTimeoutException
// in case we get a ConnectTimeoutException
//
int nRetry = 10;
while (--nRetry > 0)
Expand Down Expand Up @@ -260,6 +260,9 @@ allTests(Test::TestHelper* helper)
{
ControllerPrx controller(helper->communicator(), "controller:" + helper->getTestEndpoint(1));

// Make sure the controller is connected before we proceed.
connect(controller);

try
{
allTestsWithController(helper, controller);
Expand Down
10 changes: 6 additions & 4 deletions csharp/test/Ice/timeout/AllTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ private static Ice.Connection connect(ObjectPrx prx)

public static async Task allTests(global::Test.TestHelper helper)
{
Test.ControllerPrx controller =
Test.ControllerPrxHelper.checkedCast(
helper.communicator().stringToProxy("controller:" + helper.getTestEndpoint(1)));
test(controller != null);
Test.ControllerPrx controller = Test.ControllerPrxHelper.createProxy(
helper.communicator(),
"controller:" + helper.getTestEndpoint(1));

// Make sure the controller is connected before we proceed.
_ = connect(controller);

try
{
Expand Down
40 changes: 25 additions & 15 deletions java/test/src/main/java/test/Ice/timeout/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,26 @@ private static void test(boolean b) {
}
}

private static com.zeroc.Ice.Connection connect(com.zeroc.Ice.ObjectPrx prx) {
int nRetry = 10;
while (--nRetry > 0) {
try {
prx.ice_getConnection();
break;
} catch (com.zeroc.Ice.ConnectTimeoutException ex) {
// Can sporadically occur with slow machines
}
}
return prx.ice_getConnection(); // Establish connection
}

public static void allTests(test.TestHelper helper) {
ControllerPrx controller =
ControllerPrx.checkedCast(
helper.communicator()
.stringToProxy("controller:" + helper.getTestEndpoint(1)));
test(controller != null);
var controller =
ControllerPrx.createProxy(
helper.communicator(), "controller:" + helper.getTestEndpoint(1));

// Make sure the controller is connected before we proceed.
connect(controller);

try {
allTestsWithController(helper, controller);
Expand Down Expand Up @@ -139,21 +153,17 @@ public static void allTestsWithController(test.TestHelper helper, ControllerPrx
out.print("testing close timeout... ");
out.flush();
{
//
// This test wants to call some local methods while our connection is in the `Closing`
// state,
// before it eventually transitions to the `Closed` state due to hitting the close
// timeout.
// state, before it eventually transitions to the `Closed` state due to hitting the
// close timeout.
//
// However, in Java `close` blocks until the connection is closed. So, in order to
// access the
// `Closing` state, we initiate the close in a separate thread, wait 50ms to let the
// thread
// start the closure process, and hope that we're in the `Closing` state by then.
//
// access the `Closing` state, we initiate the close in a separate thread, wait 50ms to
// let the thread start the closure process, and hope that we're in the `Closing` state
// by then.

// Get the connection, and put the OA in the `Hold` state.
var connection = timeout.ice_getConnection();
var connection = connect(timeout);
controller.holdAdapter(-1);

// Initiate the connection closure.
Expand Down
2 changes: 2 additions & 0 deletions matlab/test/Ice/timeout/AllTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function allTests(helper)
import Test.*;

controller = ControllerPrx(helper.communicator(), ['controller:', helper.getTestEndpoint(1)]);
AllTests.connect(controller);

try
AllTests.allTestsWithController(helper, controller);
catch ex
Expand Down
2 changes: 2 additions & 0 deletions php/test/Ice/timeout/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function allTests($helper)
$communicator,
sprintf("controller:%s", $helper->getTestEndpoint(1)));

connect($controller);

try
{
allTestsWithController($helper, $controller);
Expand Down
50 changes: 6 additions & 44 deletions python/test/Ice/timeout/AllTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,12 @@
import Ice
import Test
import sys
import threading


def test(b):
if not b:
raise RuntimeError("test assertion failed")


class CallbackBase:
def __init__(self):
self._called = False
self._cond = threading.Condition()

def called(self):
with self._cond:
self._called = True
self._cond.notify()

def check(self):
with self._cond:
while not self._called:
self._cond.wait()
self._called = False
return True


class Callback(CallbackBase):
def response(self):
self.called()

def exception(self, ex):
test(False)

def responseEx(self):
test(False)

def exceptionEx(self, ex):
test(isinstance(ex, Ice.TimeoutException))
self.called()


def connect(prx):
# Establish connection with the given proxy (which might have a timeout
# set and might sporadically fail on connection establishment if it's
Expand All @@ -64,7 +29,7 @@ def connect(prx):

def allTests(helper, communicator):
controller = Test.ControllerPrx(communicator, f"controller:{helper.getTestEndpoint(num=1)}")
test(controller is not None)
connect(controller)

try:
allTestsWithController(helper, communicator, controller)
Expand All @@ -76,23 +41,20 @@ def allTests(helper, communicator):


def allTestsWithController(helper, communicator, controller):
obj = Ice.ObjectPrx(communicator, f"timeout:{helper.getTestEndpoint()}")

timeout = Test.TimeoutPrx.checkedCast(obj)
test(timeout is not None)
timeout = Test.TimeoutPrx(communicator, f"timeout:{helper.getTestEndpoint()}")

sys.stdout.write("testing invocation timeout... ")
sys.stdout.flush()
connection = obj.ice_getConnection()
to = Test.TimeoutPrx.uncheckedCast(obj.ice_invocationTimeout(100))
connection = timeout.ice_getConnection()
to = timeout.ice_invocationTimeout(100)
test(connection == to.ice_getConnection())
try:
to.sleep(1000)
test(False)
except Ice.InvocationTimeoutException:
pass
obj.ice_ping()
to = Test.TimeoutPrx.uncheckedCast(obj.ice_invocationTimeout(1000))
timeout.ice_ping()
to = timeout.ice_invocationTimeout(1000)
test(connection == to.ice_getConnection())
try:
to.sleep(100)
Expand Down
1 change: 1 addition & 0 deletions ruby/test/Ice/timeout/AllTests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def connect(prx)

def allTests(helper, communicator)
controller = Test::ControllerPrx.new(communicator, "controller:#{helper.getTestEndpoint(num:1)}")
connect(controller)
begin
allTestsWithController(helper, communicator, controller)
rescue
Expand Down
11 changes: 7 additions & 4 deletions swift/test/Ice/timeout/AllTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ func connect(_ prx: Ice.ObjectPrx) async throws -> Ice.Connection {
}

public func allTests(helper: TestHelper) async throws {
let controller = try await checkedCast(
prx: helper.communicator().stringToProxy("controller:\(helper.getTestEndpoint(num: 1))")!,
type: ControllerPrx.self
)!
let controller = try makeProxy(
communicator: helper.communicator(),
proxyString: "controller:\(helper.getTestEndpoint(num: 1))",
type: ControllerPrx.self)

try await connect(controller)

do {
try await allTestsWithController(helper: helper, controller: controller)
} catch {
Expand Down

0 comments on commit 41307f9

Please sign in to comment.