Esempio n. 1
0
        public static void allTestsWithController(TestHelper helper, IControllerPrx controller)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            var timeout = ITimeoutPrx.Parse($"timeout:{helper.GetTestEndpoint(0)}", communicator);

            System.IO.TextWriter output = helper.GetWriter();
            output.Write("testing connect timeout... ");
            output.Flush();
            {
                //
                // Expect ConnectTimeoutException.
                //
                ITimeoutPrx to = timeout.Clone(connectionTimeout: 100);
                controller.holdAdapter(-1);
                try
                {
                    to.op();
                    TestHelper.Assert(false);
                }
                catch (ConnectTimeoutException)
                {
                    // Expected.
                }
                controller.resumeAdapter();
                timeout.op(); // Ensure adapter is active.
            }
            {
                //
                // Expect success.
                //
                ITimeoutPrx to = timeout.Clone(connectionTimeout: -1);
                controller.holdAdapter(100);
                to.op();
            }
            output.WriteLine("ok");

            // The sequence needs to be large enough to fill the write/recv buffers
            byte[] seq = new byte[2000000];

            // TODO: remove or refactor depending on what we decide for connection timeouts
            // output.Write("testing connection timeout... ");
            // output.Flush();
            // {
            //     //
            //     // Expect TimeoutException.
            //     //
            //     var to = timeout.Clone(connectionTimeout: 250);
            //     connect(to);
            //     controller.holdAdapter(-1);
            //     try
            //     {
            //         to.sendData(seq);
            //         test(false);
            //     }
            //     catch (ConnectionTimeoutException)
            //     {
            //         // Expected.
            //     }
            //     controller.resumeAdapter();
            //     timeout.op(); // Ensure adapter is active.
            // }
            // {
            //     //
            //     // Expect success.
            //     //
            //     var to = timeout.Clone(connectionTimeout: 2000);
            //     controller.holdAdapter(100);
            //     try
            //     {
            //         to.sendData(new byte[1000000]);
            //     }
            //     catch (ConnectionTimeoutException)
            //     {
            //         test(false);
            //     }
            // }
            // output.WriteLine("ok");

            output.Write("testing invocation timeout... ");
            output.Flush();
            {
                timeout.IcePing(); // Makes sure a working connection is associated with the proxy
                var connection = timeout.GetConnection();
                var to         = timeout.Clone(invocationTimeout: 100);
                TestHelper.Assert(connection == to.GetConnection());
                try
                {
                    to.sleep(1000);
                    TestHelper.Assert(false);
                }
                catch (TimeoutException)
                {
                }
                timeout.IcePing();
                to = timeout.Clone(invocationTimeout: 1000);
                TestHelper.Assert(connection == to.GetConnection());
                try
                {
                    to.sleep(100);
                }
                catch (TimeoutException)
                {
                    TestHelper.Assert(false);
                }
                TestHelper.Assert(connection == to.GetConnection());
            }
            {
                //
                // Expect TimeoutException.
                //
                var to = timeout.Clone(invocationTimeout: 100);
                try
                {
                    to.sleepAsync(1000).Wait();
                }
                catch (AggregateException ex) when(ex.InnerException is TimeoutException)
                {
                }
                timeout.IcePing();
            }
            {
                //
                // Expect success.
                //
                var to = timeout.Clone(invocationTimeout: 1000);
                to.sleepAsync(100).Wait();
            }

            output.WriteLine("ok");

            // TODO: remove or refactor depending on what we decide for connection timeouts
            // output.Write("testing close timeout... ");
            // output.Flush();
            // {
            //     var to = timeout.Clone(connectionTimeout: 250);
            //     var connection = connect(to);
            //     controller.holdAdapter(-1);
            //     connection.Close(Ice.ConnectionClose.GracefullyWithWait);
            //     try
            //     {
            //         _ = connection.GetConnectionInfo(); // getInfo() doesn't throw in the closing state.
            //     }
            //     catch (System.Exception)
            //     {
            //         test(false);
            //     }
            //
            //     while (true)
            //     {
            //         try
            //         {
            //             _ = connection.GetConnectionInfo();
            //             Thread.Sleep(10);
            //         }
            //         catch (ConnectionClosedLocallyException ex)
            //         {
            //             // Expected (graceful closure)
            //             break;
            //         }
            //     }
            //     controller.resumeAdapter();
            //     timeout.op(); // Ensure adapter is active.
            // }
            // output.WriteLine("ok");

            output.Write("testing timeout overrides... ");
            output.Flush();
            // TODO: remove or refactor depending on what we decide for connection timeouts
            // {
            //     //
            //     // Test Ice.Override.Timeout. This property overrides all
            //     // endpoint timeouts.
            //     //
            //     var properties = communicator.GetProperties();
            //     properties["Ice.Override.ConnectTimeout"] = "250";
            //     properties["Ice.Override.Timeout"] = "100";
            //     var comm = helper.initialize(properties);
            //     var to = ITimeoutPrx.Parse(sref, comm);
            //     connect(to);
            //     controller.holdAdapter(-1);
            //     try
            //     {
            //         to.sendData(seq);
            //         test(false);
            //     }
            //     catch (ConnectionTimeoutException)
            //     {
            //         // Expected.
            //     }
            //     controller.resumeAdapter();
            //     timeout.op(); // Ensure adapter is active.

            //     //
            //     // Calling ice_timeout() should have no effect.
            //     //
            //     to = to.Clone(connectionTimeout: 1000);
            //     connect(to);
            //     controller.holdAdapter(-1);
            //     try
            //     {
            //         to.sendData(seq);
            //         test(false);
            //     }
            //     catch (ConnectionTimeoutException)
            //     {
            //         // Expected.
            //     }
            //     controller.resumeAdapter();
            //     timeout.op(); // Ensure adapter is active.
            //     comm.Destroy();
            // }

            {
                //
                // Test Ice.Override.ConnectTimeout.
                //
                var properties = communicator.GetProperties();
                properties["Ice.Override.ConnectTimeout"] = "250";
                var comm = helper.Initialize(properties);
                controller.holdAdapter(-1);
                var to = ITimeoutPrx.Parse($"timeout:{helper.GetTestEndpoint(0)}", comm);
                try
                {
                    to.op();
                    TestHelper.Assert(false);
                }
                catch (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.Clone(connectionTimeout: 1000);
                try
                {
                    to.op();
                    TestHelper.Assert(false);
                }
                catch (ConnectTimeoutException)
                {
                    // Expected.
                }
                controller.resumeAdapter();
                timeout.op(); // Ensure adapter is active.

                //
                // Verify that timeout set via ice_timeout() is still used for requests.
                //
                // to = to.Clone(connectionTimeout: 250);
                // connect(to);
                // controller.holdAdapter(-1);
                // try
                // {
                //     to.sendData(seq);
                //     test(false);
                // }
                // catch (ConnectionTimeoutException)
                // {
                //     // Expected.
                // }
                // controller.resumeAdapter();
                // timeout.op(); // Ensure adapter is active.
                comm.Destroy();
            }
            // TODO: remove or refactor depending on what we decide for connection timeouts
            // {
            //     //
            //     // Test Ice.Override.CloseTimeout.
            //     //
            //     var properties = communicator.GetProperties();
            //     properties["Ice.Override.CloseTimeout"] = "100";
            //     var comm = helper.initialize(properties);
            //     IObjectPrx.Parse(sref, comm).GetConnection();
            //     controller.holdAdapter(-1);
            //     long begin = System.DateTime.Now.Ticks;
            //     comm.Destroy();
            //     test(((long)new System.TimeSpan(System.DateTime.Now.Ticks - begin).TotalMilliseconds - begin) < 1000);
            //     controller.resumeAdapter();
            // }
            output.WriteLine("ok");

            output.Write("testing invocation timeouts with collocated calls... ");
            output.Flush();
            {
                communicator.SetProperty("TimeoutCollocated.AdapterId", "timeoutAdapter");

                var adapter = communicator.CreateObjectAdapter("TimeoutCollocated");
                adapter.Activate();

                var proxy = adapter.AddWithUUID(new Timeout(), ITimeoutPrx.Factory).Clone(invocationTimeout: 100);
                try
                {
                    proxy.sleep(500);
                    TestHelper.Assert(false);
                }
                catch (TimeoutException)
                {
                }

                try
                {
                    proxy.sleepAsync(500).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ex) when(ex.InnerException is TimeoutException)
                {
                }
                adapter.Destroy();
            }
            output.WriteLine("ok");

            controller.shutdown();
        }
Esempio n. 2
0
        public static void allTestsWithController(TestHelper helper, IControllerPrx controller)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);

            var timeout = ITimeoutPrx.Parse($"timeout:{helper.GetTestEndpoint(0)}", communicator);

            System.IO.TextWriter output = helper.GetWriter();
            output.Write("testing connect timeout... ");
            output.Flush();
            {
                var properties = communicator.GetProperties();
                properties["Ice.ConnectTimeout"] = "100ms";
                using var comm = new Communicator(properties);

                var to = ITimeoutPrx.Parse($"timeout:{helper.GetTestEndpoint(0)}", comm);

                // Expect ConnectTimeoutException.
                controller.holdAdapter(-1);
                try
                {
                    to.op();
                    TestHelper.Assert(false);
                }
                catch (ConnectTimeoutException)
                {
                    // Expected.
                }
                controller.resumeAdapter();
                timeout.op(); // Ensure adapter is active.
            }
            {
                //
                // Expect success.
                //
                controller.holdAdapter(100);
                timeout.op();
            }
            output.WriteLine("ok");

            // The sequence needs to be large enough to fill the write/recv buffers
            byte[] seq = new byte[2000000];

            output.Write("testing connection timeout... ");
            output.Flush();
            {
                //
                // Expect TimeoutException.
                //
                controller.holdAdapter(-1);
                timeout.GetConnection() !.Acm = new Acm(TimeSpan.FromMilliseconds(50),
                                                        AcmClose.OnInvocationAndIdle,
                                                        AcmHeartbeat.Off);
                try
                {
                    timeout.sendData(seq);
                    TestHelper.Assert(false);
                }
                catch (ConnectionTimeoutException)
                {
                    // Expected.
                }
                controller.resumeAdapter();
                timeout.op(); // Ensure adapter is active.
            }
            {
                //
                // Expect success.
                //
                controller.holdAdapter(100);
                try
                {
                    timeout.sendData(new byte[1000000]);
                }
                catch (ConnectionTimeoutException)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("testing invocation timeout... ");
            output.Flush();
            {
                timeout.IcePing(); // Makes sure a working connection is associated with the proxy
                var connection = timeout.GetConnection();
                var to         = timeout.Clone(invocationTimeout: 100);
                TestHelper.Assert(connection == to.GetConnection());
                try
                {
                    to.sleep(1000);
                    TestHelper.Assert(false);
                }
                catch (TimeoutException)
                {
                }
                timeout.IcePing();
                to = timeout.Clone(invocationTimeout: 1000);
                TestHelper.Assert(connection == to.GetConnection());
                try
                {
                    to.sleep(100);
                }
                catch (TimeoutException)
                {
                    TestHelper.Assert(false);
                }
                TestHelper.Assert(connection == to.GetConnection());
            }
            {
                //
                // Expect TimeoutException.
                //
                var to = timeout.Clone(invocationTimeout: 100);
                try
                {
                    to.sleepAsync(1000).Wait();
                }
                catch (AggregateException ex) when(ex.InnerException is TimeoutException)
                {
                }
                timeout.IcePing();
            }
            {
                //
                // Expect success.
                //
                var to = timeout.Clone(invocationTimeout: 1000);
                to.sleepAsync(100).Wait();
            }

            output.WriteLine("ok");

            output.Write("testing close timeout... ");
            output.Flush();
            {
                var properties = communicator.GetProperties();
                properties["Ice.CloseTimeout"] = "100ms";
                using var comm = new Communicator(properties);

                var to = ITimeoutPrx.Parse($"timeout:{helper.GetTestEndpoint(0)}", comm);

                var connection  = to.GetConnection();
                var connection2 = timeout.GetConnection(); // No close timeout

                TestHelper.Assert(connection != null && connection2 != null);

                controller.holdAdapter(-1);

                // Make sure there's no ReadAsync pending
                _ = to.IcePingAsync();
                _ = timeout.IcePingAsync();

                var semaphore = new System.Threading.SemaphoreSlim(0);
                connection.Closed += (sender, args) => semaphore.Release();
                connection.Close(ConnectionClose.Gracefully);
                TestHelper.Assert(semaphore.Wait(500));

                connection2.Closed += (sender, args) => semaphore.Release();
                connection2.Close(ConnectionClose.Gracefully);
                TestHelper.Assert(!semaphore.Wait(500));

                controller.resumeAdapter();
                timeout.op(); // Ensure adapter is active.
            }
            output.WriteLine("ok");

            output.Write("testing invocation timeouts with collocated calls... ");
            output.Flush();
            {
                communicator.SetProperty("TimeoutCollocated.AdapterId", "timeoutAdapter");

                var adapter = communicator.CreateObjectAdapter("TimeoutCollocated");
                adapter.Activate();

                var proxy = adapter.AddWithUUID(new Timeout(), ITimeoutPrx.Factory).Clone(invocationTimeout: 100);
                try
                {
                    proxy.sleep(500);
                    TestHelper.Assert(false);
                }
                catch (TimeoutException)
                {
                }

                try
                {
                    proxy.sleepAsync(500).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ex) when(ex.InnerException is TimeoutException)
                {
                }
                adapter.Dispose();
            }
            output.WriteLine("ok");

            controller.shutdown();
        }