diff --git a/cpp/src/Ice/ConnectionI.cpp b/cpp/src/Ice/ConnectionI.cpp index cbf9fa34187..a8704a428fe 100644 --- a/cpp/src/Ice/ConnectionI.cpp +++ b/cpp/src/Ice/ConnectionI.cpp @@ -39,15 +39,38 @@ using namespace IceInternal; namespace { - class TimeoutCallback final : public IceUtil::TimerTask + class ConnectTimerTask : public IceUtil::TimerTask { public: - TimeoutCallback(Ice::ConnectionI* connection) : _connection(connection) {} + ConnectTimerTask(const Ice::ConnectionIPtr& connection) : _connection(connection) {} - void runTimerTask() final { _connection->timedOut(); } + void runTimerTask() override + { + if (auto connection = _connection.lock()) + { + connection->connectTimedOut(); + } + } private: - Ice::ConnectionI* _connection; + const weak_ptr _connection; + }; + + class CloseTimerTask : public IceUtil::TimerTask + { + public: + CloseTimerTask(const Ice::ConnectionIPtr& connection) : _connection(connection) {} + + void runTimerTask() override + { + if (auto connection = _connection.lock()) + { + connection->closeTimedOut(); + } + } + + private: + const weak_ptr _connection; }; class ExecuteUpCall final : public ExecutorWorkItem @@ -391,6 +414,11 @@ Ice::ConnectionI::startAsync( if (!initialize() || !validate()) { + if (_connectTimeout > chrono::seconds::zero()) + { + _timer->schedule(make_shared(shared_from_this()), _connectTimeout); + } + if (connectionStartCompleted && connectionStartFailed) { _connectionStartCompleted = std::move(connectionStartCompleted); @@ -1326,8 +1354,6 @@ Ice::ConnectionI::message(ThreadPoolCurrent& current) try { - unscheduleTimeout(current.operation); - SocketOperation writeOp = SocketOperationNone; SocketOperation readOp = SocketOperationNone; @@ -1473,7 +1499,6 @@ Ice::ConnectionI::message(ThreadPoolCurrent& current) // for data to read or write. if (newOp) { - scheduleTimeout(newOp); _threadPool->update(shared_from_this(), current.operation, newOp); return; } @@ -1539,11 +1564,10 @@ Ice::ConnectionI::message(ThreadPoolCurrent& current) } } - // If the connection is not closed yet, we can schedule the read or write timeout and update the thread - // pool selector to wait for readiness of read, write or both operations. + // If the connection is not closed yet, we update the thread pool selector to wait for readiness of + // read, write or both operations. if (_state < StateClosed) { - scheduleTimeout(newOp); _threadPool->update(shared_from_this(), current.operation, newOp); } } @@ -1769,12 +1793,6 @@ ConnectionI::upcall( void Ice::ConnectionI::finished(ThreadPoolCurrent& current, bool close) { - { - std::lock_guard lock(_mutex); - assert(_state == StateClosed); - unscheduleTimeout(static_cast(SocketOperationRead | SocketOperationWrite)); - } - // If there are no callbacks to call, we don't call ioCompleted() since we're not going to call code that will // potentially block (this avoids promoting a new leader and unecessary thread creation, especially if this is // called on shutdown). @@ -1979,24 +1997,6 @@ Ice::ConnectionI::getNativeInfo() return _transceiver->getNativeInfo(); } -void -Ice::ConnectionI::timedOut() -{ - std::lock_guard lock(_mutex); - if (_state <= StateNotValidated) - { - setState(StateClosed, make_exception_ptr(ConnectTimeoutException(__FILE__, __LINE__))); - } - else if (_state < StateClosing) - { - setState(StateClosed, make_exception_ptr(TimeoutException(__FILE__, __LINE__))); - } - else if (_state < StateClosed) - { - setState(StateClosed, make_exception_ptr(CloseTimeoutException(__FILE__, __LINE__))); - } -} - string Ice::ConnectionI::type() const noexcept { @@ -2061,10 +2061,6 @@ Ice::ConnectionI::ConnectionI( _logger(_instance->initializationData().logger), // Cached for better performance. _traceLevels(_instance->traceLevels()), // Cached for better performance. _timer(_instance->timer()), // Cached for better performance. - _writeTimeout(new TimeoutCallback(this)), - _writeTimeoutScheduled(false), - _readTimeout(new TimeoutCallback(this)), - _readTimeoutScheduled(false), _connectTimeout(options.connectTimeout), _closeTimeout(options.closeTimeout), _inactivityTimeout(options.inactivityTimeout), @@ -2472,6 +2468,11 @@ Ice::ConnectionI::initiateShutdown() os.write(static_cast(1)); // compression status: compression supported but not used. os.write(headerSize); // Message size. + if (_closeTimeout > chrono::seconds::zero()) + { + _timer->schedule(make_shared(shared_from_this()), _closeTimeout); + } + OutgoingMessage message(&os, false); if (sendMessage(message) & AsyncStatusSent) { @@ -2483,7 +2484,6 @@ Ice::ConnectionI::initiateShutdown() SocketOperation op = _transceiver->closing(true, _exception); if (op) { - scheduleTimeout(op); _threadPool->_register(shared_from_this(), op); } } @@ -2530,6 +2530,28 @@ Ice::ConnectionI::idleCheck( // else, nothing to do } +void +Ice::ConnectionI::connectTimedOut() noexcept +{ + std::lock_guard lock(_mutex); + if (_state < StateActive) + { + setState(StateClosed, make_exception_ptr(ConnectTimeoutException(__FILE__, __LINE__))); + } + // else ignore since we're already connected. +} + +void +Ice::ConnectionI::closeTimedOut() noexcept +{ + std::lock_guard lock(_mutex); + if (_state < StateClosed) + { + setState(StateClosed, make_exception_ptr(CloseTimeoutException(__FILE__, __LINE__))); + } + // else ignore since we're already closed. +} + void Ice::ConnectionI::sendHeartbeat() noexcept { @@ -2627,7 +2649,6 @@ Ice::ConnectionI::initialize(SocketOperation operation) SocketOperation s = _transceiver->initialize(_readStream, _writeStream); if (s != SocketOperationNone) { - scheduleTimeout(s); _threadPool->update(shared_from_this(), operation, s); return false; } @@ -2674,7 +2695,6 @@ Ice::ConnectionI::validate(SocketOperation operation) SocketOperation op = write(_writeStream); if (op) { - scheduleTimeout(op); _threadPool->update(shared_from_this(), operation, op); return false; } @@ -2703,7 +2723,6 @@ Ice::ConnectionI::validate(SocketOperation operation) SocketOperation op = read(_readStream); if (op) { - scheduleTimeout(op); _threadPool->update(shared_from_this(), operation, op); return false; } @@ -2932,6 +2951,7 @@ Ice::ConnectionI::sendNextMessages(vector& callbacks) AsyncStatus Ice::ConnectionI::sendMessage(OutgoingMessage& message) { + assert(_state >= StateActive); assert(_state < StateClosed); message.stream->i = 0; // Reset the message stream iterator before starting sending the message. @@ -3058,7 +3078,6 @@ Ice::ConnectionI::sendMessage(OutgoingMessage& message) #endif _writeStream.swap(*_sendStreams.back().stream); - scheduleTimeout(op); _threadPool->_register(shared_from_this(), op); return AsyncStatusQueued; } @@ -3290,6 +3309,10 @@ Ice::ConnectionI::parseMessage( SocketOperation op = _transceiver->closing(false, _exception); if (op) { + if (_closeTimeout > chrono::seconds::zero()) + { + _timer->schedule(make_shared(shared_from_this()), _closeTimeout); + } return op; } setState(StateClosed); @@ -3509,75 +3532,6 @@ Ice::ConnectionI::dispatchAll( } } -void -Ice::ConnectionI::scheduleTimeout(SocketOperation status) -{ - int timeout; - if (_state < StateActive) - { - timeout = static_cast(chrono::milliseconds(_connectTimeout).count()); - } - else if (_state < StateClosingPending) - { - if (_readHeader) // No timeout for reading the header. - { - status = static_cast(status & ~SocketOperationRead); - } - timeout = _endpoint->timeout(); - } - else - { - timeout = static_cast(chrono::milliseconds(_closeTimeout).count()); - } - - if (timeout < 0) - { - return; - } - - try - { - if (status & IceInternal::SocketOperationRead) - { - if (_readTimeoutScheduled) - { - _timer->cancel(_readTimeout); - } - _timer->schedule(_readTimeout, chrono::milliseconds(timeout)); - _readTimeoutScheduled = true; - } - - if (status & (IceInternal::SocketOperationWrite | IceInternal::SocketOperationConnect)) - { - if (_writeTimeoutScheduled) - { - _timer->cancel(_writeTimeout); - } - _timer->schedule(_writeTimeout, chrono::milliseconds(timeout)); - _writeTimeoutScheduled = true; - } - } - catch (const IceUtil::Exception&) - { - assert(false); - } -} - -void -Ice::ConnectionI::unscheduleTimeout(SocketOperation status) -{ - if ((status & IceInternal::SocketOperationRead) && _readTimeoutScheduled) - { - _timer->cancel(_readTimeout); - _readTimeoutScheduled = false; - } - if ((status & (IceInternal::SocketOperationWrite | IceInternal::SocketOperationConnect)) && _writeTimeoutScheduled) - { - _timer->cancel(_writeTimeout); - _writeTimeoutScheduled = false; - } -} - Ice::ConnectionInfoPtr Ice::ConnectionI::initConnectionInfo() const { diff --git a/cpp/src/Ice/ConnectionI.h b/cpp/src/Ice/ConnectionI.h index 8ffb4265c12..60309c07f47 100644 --- a/cpp/src/Ice/ConnectionI.h +++ b/cpp/src/Ice/ConnectionI.h @@ -194,8 +194,6 @@ namespace Ice std::string toString() const noexcept final; // From Connection and EventHandler. IceInternal::NativeInfoPtr getNativeInfo() final; - void timedOut(); - std::string type() const noexcept final; // From Connection. std::int32_t timeout() const noexcept final; // From Connection. ConnectionInfoPtr getInfo() const final; // From Connection @@ -230,6 +228,12 @@ namespace Ice void idleCheck(const IceUtil::TimerTaskPtr& idleCheckTimerTask, const std::chrono::seconds& idleTimeout) noexcept; + /// Aborts the connection if its state is < StateActive. + void connectTimedOut() noexcept; + + /// Aborts the connection if its state is < StateClosed. + void closeTimedOut() noexcept; + // TODO: there are too many functions with similar names. This is the function called by the HeartbeatTimerTask. void sendHeartbeat() noexcept; @@ -302,9 +306,6 @@ namespace Ice void dispatchAll(Ice::InputStream&, std::int32_t, std::int32_t, std::uint8_t, const ObjectAdapterIPtr&); - void scheduleTimeout(IceInternal::SocketOperation status); - void unscheduleTimeout(IceInternal::SocketOperation status); - Ice::ConnectionInfoPtr initConnectionInfo() const; Ice::Instrumentation::ConnectionState toConnectionState(State) const; @@ -332,10 +333,6 @@ namespace Ice const IceInternal::ThreadPoolPtr _threadPool; const IceUtil::TimerPtr _timer; - const IceUtil::TimerTaskPtr _writeTimeout; - bool _writeTimeoutScheduled; - const IceUtil::TimerTaskPtr _readTimeout; - bool _readTimeoutScheduled; const std::chrono::seconds _connectTimeout; const std::chrono::seconds _closeTimeout; diff --git a/cpp/src/Ice/OutgoingAsync.cpp b/cpp/src/Ice/OutgoingAsync.cpp index 497200ff4f4..82b4ed7d988 100644 --- a/cpp/src/Ice/OutgoingAsync.cpp +++ b/cpp/src/Ice/OutgoingAsync.cpp @@ -606,14 +606,7 @@ ProxyOutgoingAsyncBase::responseImpl(bool ok, bool invoke) void ProxyOutgoingAsyncBase::runTimerTask() { - if (_proxy._getReference()->getInvocationTimeout() == -2) - { - cancel(make_exception_ptr(ConnectionTimeoutException(__FILE__, __LINE__))); - } - else - { - cancel(make_exception_ptr(InvocationTimeoutException(__FILE__, __LINE__))); - } + cancel(make_exception_ptr(InvocationTimeoutException(__FILE__, __LINE__))); } OutgoingAsync::OutgoingAsync(ObjectPrx proxy, bool synchronous) diff --git a/cpp/test/Ice/metrics/AllTests.cpp b/cpp/test/Ice/metrics/AllTests.cpp index d6d18af9116..687144507f6 100644 --- a/cpp/test/Ice/metrics/AllTests.cpp +++ b/cpp/test/Ice/metrics/AllTests.cpp @@ -202,7 +202,8 @@ namespace } else if (view[map].size() != 1 || view[map][0]->id != value) { - cerr << "invalid attribute value: " << attr << " = " << value << " got " << view[map][0]->id << endl; + cerr << "size of view[map] is: " << view[map].size() << endl; + cerr << "expected value for attribute " << attr << " = " << value << "; got " << view[map][0]->id << endl; test(false); } @@ -610,37 +611,8 @@ allTests(Test::TestHelper* helper, const CommunicatorObserverIPtr& obsv) metrics->ice_getConnection()->close(Ice::ConnectionClose::GracefullyWithWait); - metrics->ice_timeout(500)->ice_ping(); - controller->hold(); - try - { - Ice::ByteSeq seq; - seq.resize(10000000); - metrics->ice_timeout(500)->opByteS(seq); - test(false); - } - catch (const Ice::TimeoutException&) - { - } - controller->resume(); - - cm1 = dynamic_pointer_cast( - clientMetrics->getMetricsView("View", timestamp)["Connection"][0]); - while (true) - { - sm1 = dynamic_pointer_cast( - serverMetrics->getMetricsView("View", timestamp)["Connection"][0]); - if (sm1->failures >= 2) - { - break; - } - this_thread::sleep_for(chrono::milliseconds(10)); - } - test(cm1->failures == 2 && sm1->failures >= 2); - - checkFailure(clientMetrics, "Connection", cm1->id, "::Ice::TimeoutException", 1); - checkFailure(clientMetrics, "Connection", cm1->id, "::Ice::ConnectTimeoutException", 1); - checkFailure(serverMetrics, "Connection", sm1->id, "::Ice::ConnectionLostException"); + // TODO: this appears necessary on slow macos VMs to give time to the server to clean-up the connection. + this_thread::sleep_for(chrono::milliseconds(100)); MetricsPrx m = metrics->ice_timeout(500)->ice_connectionId("Con1"); m->ice_ping(); diff --git a/cpp/test/Ice/metrics/Client.cpp b/cpp/test/Ice/metrics/Client.cpp index 5dde8f07d6e..8bd7838e5cd 100644 --- a/cpp/test/Ice/metrics/Client.cpp +++ b/cpp/test/Ice/metrics/Client.cpp @@ -25,6 +25,7 @@ Client::run(int argc, char** argv) initData.properties->setProperty("Ice.Admin.InstanceName", "client"); initData.properties->setProperty("Ice.Admin.DelayCreation", "1"); initData.properties->setProperty("Ice.Warn.Connections", "0"); + initData.properties->setProperty("Ice.Connection.ConnectTimeout", "1"); // speed up connection establishment test CommunicatorObserverIPtr observer = make_shared(); initData.observer = observer; Ice::CommunicatorHolder communicator = initialize(argc, argv, initData); diff --git a/cpp/test/Ice/retry/AllTests.cpp b/cpp/test/Ice/retry/AllTests.cpp index c803a6a4a99..337530d9d06 100644 --- a/cpp/test/Ice/retry/AllTests.cpp +++ b/cpp/test/Ice/retry/AllTests.cpp @@ -251,22 +251,6 @@ allTests(const Ice::CommunicatorPtr& communicator, const Ice::CommunicatorPtr& c testRetryCount(-1); } - if (retry1->ice_getConnection()) - { - // The timeout might occur on connection establishment or because of the sleep. What's - // important here is to make sure there are 4 retries and that no calls succeed to - // ensure retries with the old connection timeout semantics work. - RetryPrx retryWithTimeout = retry1->ice_invocationTimeout(-2)->ice_timeout(200); - try - { - retryWithTimeout->sleep(1000); - test(false); - } - catch (const Ice::TimeoutException&) - { - } - testRetryCount(4); - } cout << "ok" << endl; } diff --git a/cpp/test/Ice/timeout/AllTests.cpp b/cpp/test/Ice/timeout/AllTests.cpp index f3aa1757740..e0c1dc002b2 100644 --- a/cpp/test/Ice/timeout/AllTests.cpp +++ b/cpp/test/Ice/timeout/AllTests.cpp @@ -88,47 +88,6 @@ allTestsWithController(Test::TestHelper* helper, const ControllerPrx& controller } cout << "ok" << endl; - // The sequence needs to be large enough to fill the write/recv buffers - ByteSeq seq(2000000); - - cout << "testing connection timeout... " << flush; - { - // - // Expect TimeoutException. - // - TimeoutPrx to = timeout->ice_timeout(250); - connect(to); - controller->holdAdapter(-1); - try - { - to->sendData(seq); - test(false); - } - catch (const Ice::TimeoutException&) - { - // Expected. - } - controller->resumeAdapter(); - timeout->op(); // Ensure adapter is active. - } - { - // - // Expect success. - // - TimeoutPrx to = timeout->ice_timeout(2000); - controller->holdAdapter(100); - try - { - ByteSeq seq2(1000000); - to->sendData(seq2); - } - catch (const Ice::TimeoutException&) - { - test(false); - } - } - cout << "ok" << endl; - cout << "testing invocation timeout... " << flush; { Ice::ConnectionPtr connection = timeout->ice_getConnection(); @@ -191,50 +150,6 @@ allTestsWithController(Test::TestHelper* helper, const ControllerPrx& controller test(false); } } - { - // - // Backward compatible connection timeouts - // - TimeoutPrx to = timeout->ice_invocationTimeout(-2)->ice_timeout(250); - Ice::ConnectionPtr con = connect(to); - try - { - to->sleep(750); - test(false); - } - catch (const Ice::TimeoutException&) - { - try - { - con->getInfo(); - test(false); - } - catch (const Ice::TimeoutException&) - { - // Connection got closed as well. - } - } - timeout->ice_ping(); - try - { - con = connect(to); - to->sleepAsync(750).get(); - test(false); - } - catch (const Ice::TimeoutException&) - { - try - { - con->getInfo(); - test(false); - } - catch (const Ice::TimeoutException&) - { - // Connection got closed as well. - } - } - timeout->ice_ping(); - } cout << "ok" << endl; cout << "testing close timeout... " << flush; @@ -269,123 +184,6 @@ allTestsWithController(Test::TestHelper* helper, const ControllerPrx& controller } cout << "ok" << endl; - // TODO: rework tests tests. - cout << "testing timeout overrides... " << flush; - { - // - // Test Ice.Override.Timeout. This property overrides all - // endpoint timeouts. - // - Ice::InitializationData initData; - initData.properties = communicator->getProperties()->clone(); - initData.properties->setProperty("Ice.Override.Timeout", "100"); // 100 ms - Ice::CommunicatorHolder ich(initData); - TimeoutPrx to(ich.communicator(), sref); - connect(to); - controller->holdAdapter(-1); - try - { - to->sendData(seq); - test(false); - } - catch (const Ice::TimeoutException&) - { - // Expected. - } - controller->resumeAdapter(); - timeout->op(); // Ensure adapter is active. - - // - // Calling ice_timeout() should have no effect. - // - to = to->ice_timeout(1000); - connect(to); - controller->holdAdapter(-1); - try - { - to->sendData(seq); - test(false); - } - catch (const Ice::TimeoutException&) - { - // Expected. - } - controller->resumeAdapter(); - timeout->op(); // Ensure adapter is active. - } - { - // - // Test Ice.Override.ConnectTimeout. - // - Ice::InitializationData initData; - initData.properties = communicator->getProperties()->clone(); - Ice::CommunicatorHolder ich(initData); - controller->holdAdapter(-1); - TimeoutPrx to(ich.communicator(), sref); - try - { - to->op(); - test(false); - } - catch (const Ice::ConnectTimeoutException&) - { - // Expected. - } - controller->resumeAdapter(); - timeout->op(); // Ensure adapter is active. - - // - // Calling ice_timeout() should have no effect on the connect timeout. - // - controller->holdAdapter(-1); - to = to->ice_timeout(1000); - try - { - to->op(); - test(false); - } - catch (const Ice::ConnectTimeoutException&) - { - // Expected. - } - controller->resumeAdapter(); - timeout->op(); // Ensure adapter is active. - - // - // Verify that timeout set via ice_timeout() is still used for requests. - // - to = to->ice_timeout(250); - connect(to); - controller->holdAdapter(-1); - try - { - to->sendData(seq); - test(false); - } - catch (const Ice::TimeoutException&) - { - // Expected. - } - controller->resumeAdapter(); - timeout->op(); // Ensure adapter is active. - } - { - // - // Test Ice.Override.CloseTimeout. - // - Ice::InitializationData initData; - initData.properties = communicator->getProperties()->clone(); - Ice::CommunicatorHolder ich(initData); - Ice::ConnectionPtr connection = ich->stringToProxy(sref)->ice_getConnection(); - controller->holdAdapter(-1); - auto now = chrono::steady_clock::now(); - ich.release()->destroy(); - test(chrono::steady_clock::now() - now < chrono::seconds(2)); - controller->resumeAdapter(); - timeout->op(); // Ensure adapter is active. - } - cout << "ok" << endl; - cout << "testing invocation timeouts with collocated calls... " << flush; { communicator->getProperties()->setProperty("TimeoutCollocated.AdapterId", "timeoutAdapter"); diff --git a/matlab/test/Ice/timeout/AllTests.m b/matlab/test/Ice/timeout/AllTests.m index 34643ba816d..a34306a729f 100644 --- a/matlab/test/Ice/timeout/AllTests.m +++ b/matlab/test/Ice/timeout/AllTests.m @@ -48,45 +48,6 @@ function allTestsWithController(helper, controller) timeout = TimeoutPrx.checkedCast(obj); assert(~isempty(timeout)); - % The sequence needs to be large enough to fill the write/recv buffers - bufSize = 2000000; - seq = zeros(1, bufSize, 'uint8'); - - fprintf('testing connection timeout... '); - - % - % Expect TimeoutException. - % - to = timeout.ice_timeout(250); - AllTests.connect(to); - controller.holdAdapter(-1); - try - to.sendData(seq); - assert(false); - catch ex - % Expected. - assert(isa(ex, 'Ice.TimeoutException')); - end - controller.resumeAdapter(); - timeout.op(); % Ensure adapter is active. - - % - % Expect success. - % - to = timeout.ice_timeout(2000); - controller.holdAdapter(500); - try - to.sendData(zeros(1, 1000000, 'uint8')); - catch ex - if isa(ex, 'Ice.TimeoutException') - assert(false); - else - rethrow(ex); - end - end - - fprintf('ok\n'); - fprintf('testing invocation timeout... '); connection = obj.ice_getConnection(); @@ -131,51 +92,6 @@ function allTestsWithController(helper, controller) f = to.sleepAsync(100); f.fetchOutputs(); - % - % Backward compatible connection timeouts - % - to = timeout.ice_invocationTimeout(-2).ice_timeout(250); - con = AllTests.connect(to); - try - to.sleep(750); - assert(false); - catch ex - if isa(ex, 'Ice.TimeoutException') - assert(~isempty(con)); - try - con.getInfo(); - assert(false); - catch ex - if isa(ex, 'Ice.TimeoutException') - % Connection got closed as well. - else - rethrow(ex); - end - end - end - end - obj.ice_ping(); - - try - con = AllTests.connect(to); - to.sleepAsync(750).fetchOutputs(); - assert(false); - catch ex - assert(isa(ex, 'Ice.TimeoutException')); - assert(~isempty(con)); - try - con.getInfo(); - assert(false); - catch ex - if isa(ex, 'Ice.TimeoutException') - % Connection got closed as well. - else - rethrow(ex); - end - end - end - obj.ice_ping(); - fprintf('ok\n'); controller.shutdown(); diff --git a/php/test/Ice/timeout/Client.php b/php/test/Ice/timeout/Client.php index f4d0c9d2a30..d2b2b068803 100644 --- a/php/test/Ice/timeout/Client.php +++ b/php/test/Ice/timeout/Client.php @@ -61,47 +61,6 @@ function allTestsWithController($helper, $controller) $timeout = $timeout->ice_checkedCast("::Test::Timeout"); test($timeout); - // The sequence needs to be large enough to fill the write/recv buffers - $seq = array_fill(0, 1000000, 0x01); - echo("testing connection timeout... "); - flush(); - { - // - // Expect TimeoutException. - // - $to = $timeout->ice_timeout(250)->ice_uncheckedCast("::Test::Timeout"); - connect($to); - $controller->holdAdapter(-1); - try - { - $to->sendData($seq); - test(false); - } - catch(Ice\TimeoutException $ex) - { - // Expected. - } - $controller->resumeAdapter(); - $timeout->op(); // Ensure adapter is active. - } - { - // - // Expect success. - // - $to = $timeout->ice_timeout(2000)->ice_uncheckedCast("::Test::Timeout"); - $controller->holdAdapter(100); - try - { - $data = array_fill(0, 1000000, 0x01); - $to->sendData($data); - } - catch(Exception $ex) - { - test(false); - } - } - echo("ok\n"); - echo("testing invocation timeout... "); flush(); { @@ -123,22 +82,6 @@ function allTestsWithController($helper, $controller) $to->sleep(100); test($connection == $to->ice_getConnection()); } - { - // - // Backward compatible connection timeouts - // - $to = $timeout->ice_invocationTimeout(-2)->ice_timeout(250)->ice_uncheckedCast("::Test::Timeout"); - $con = connect($to); - try - { - $to->sleep(750); - test(false); - } - catch(Ice\TimeoutException $ex) - { - } - $timeout->ice_ping(); - } echo("ok\n"); $controller->shutdown(); diff --git a/python/test/Ice/timeout/AllTests.py b/python/test/Ice/timeout/AllTests.py index 8fbd22472ae..61166a97d2a 100644 --- a/python/test/Ice/timeout/AllTests.py +++ b/python/test/Ice/timeout/AllTests.py @@ -87,34 +87,6 @@ def allTestsWithController(helper, communicator, controller): timeout = Test.TimeoutPrx.checkedCast(obj) test(timeout is not None) - sys.stdout.write("testing connection timeout... ") - sys.stdout.flush() - # - # Expect TimeoutException. - # - seq = bytes([0 for x in range(0, 10000000)]) - to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(250)) - connect(to) - controller.holdAdapter(-1) - try: - to.sendData(seq) - test(False) - except Ice.TimeoutException: - pass # Expected. - controller.resumeAdapter() - timeout.op() # Ensure adapter is active. - # - # Expect success. - # - to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(2000)) - controller.holdAdapter(100) - try: - seq2 = bytes([0 for x in range(0, 1000000)]) - to.sendData(seq2) - except Ice.TimeoutException: - test(False) - print("ok") - sys.stdout.write("testing invocation timeout... ") sys.stdout.flush() connection = obj.ice_getConnection() diff --git a/ruby/test/Ice/timeout/AllTests.rb b/ruby/test/Ice/timeout/AllTests.rb index 6922b9dd3d7..2c6f5f1f40d 100644 --- a/ruby/test/Ice/timeout/AllTests.rb +++ b/ruby/test/Ice/timeout/AllTests.rb @@ -38,36 +38,6 @@ def allTestsWithController(helper, communicator, controller) timeout = Test::TimeoutPrx::checkedCast(obj) test(timeout) - print "testing connection timeout... " - STDOUT.flush - # - # Expect TimeoutException. - # - seq = "\0" * 10000000 # 10,000,000 entries - to = Test::TimeoutPrx::uncheckedCast(obj.ice_timeout(250)) - connect(to) - controller.holdAdapter(-1) - begin - to.sendData(seq) - test(false) - rescue Ice::TimeoutException - # Expected. - end - controller.resumeAdapter() - timeout.op() # Ensure adapter is active. - # - # Expect success. - # - to = Test::TimeoutPrx::uncheckedCast(obj.ice_timeout(2000)) - controller.holdAdapter(100) - begin - seq2 = "\0" * 1000000 # 1,000,000 entries - to.sendData(seq2) - rescue Ice::TimeoutException - test(false) - end - puts "ok" - print "testing invocation timeout... " STDOUT.flush connection = obj.ice_getConnection() diff --git a/swift/test/Ice/timeout/AllTests.swift b/swift/test/Ice/timeout/AllTests.swift index 89d427e6495..68139f74f9e 100644 --- a/swift/test/Ice/timeout/AllTests.swift +++ b/swift/test/Ice/timeout/AllTests.swift @@ -76,41 +76,6 @@ public func allTestsWithController(helper: TestHelper, controller: ControllerPrx } output.writeLine("ok") - // The sequence needs to be large enough to fill the write/recv buffers - let seq = ByteSeq(repeating: 0, count: 2_000_000) - - output.write("testing connection timeout... ") - do { - // - // Expect TimeoutException. - // - let to = timeout.ice_timeout(250) - _ = try connect(to) - try controller.holdAdapter(-1) - do { - try to.sendData(seq) - try test(false) - } catch is Ice.TimeoutException { - // Expected. - } - try controller.resumeAdapter() - try timeout.op() // Ensure adapter is active. - } - - do { - // - // Expect success. - // - let to = timeout.ice_timeout(2000) - try controller.holdAdapter(100) - do { - try to.sendData(ByteSeq(repeating: 0, count: 1_000_000)) - } catch is Ice.TimeoutException { - try test(false) - } - } - output.writeLine("ok") - output.write("testing invocation timeout... ") do { let connection = try obj.ice_getConnection() @@ -154,40 +119,6 @@ public func allTestsWithController(helper: TestHelper, controller: ControllerPrx try test(false) } } - - do { - // - // Backward compatible connection timeouts - // - let to = timeout.ice_invocationTimeout(-2).ice_timeout(250) - var con = try connect(to) - do { - try to.sleep(750) - try test(false) - } catch is Ice.TimeoutException { - do { - _ = try con.getInfo() - try test(false) - } catch is Ice.TimeoutException { - // Connection got closed as well. - } - } - try timeout.ice_ping() - - do { - con = try connect(to) - try to.sleepAsync(750).wait() - try test(false) - } catch is Ice.TimeoutException { - do { - _ = try con.getInfo() - try test(false) - } catch is Ice.TimeoutException { - // Connection got closed as well. - } - } - try obj.ice_ping() - } output.writeLine("ok") output.write("testing close timeout... ") diff --git a/swift/test/Ice/timeout/Client.swift b/swift/test/Ice/timeout/Client.swift index b9751f6bf78..d3f824edd3d 100644 --- a/swift/test/Ice/timeout/Client.swift +++ b/swift/test/Ice/timeout/Client.swift @@ -8,7 +8,10 @@ import TestCommon class Client: TestHelperI { override public func run(args: [String]) throws { do { - let communicator = try initialize(args) + let properties = try createTestProperties(args) + properties.setProperty(key: "Ice.Connection.ConnectTimeout", value: "1") + properties.setProperty(key: "Ice.Connection.CloseTimeout", value: "1") + let communicator = try initialize(properties) defer { communicator.destroy() }