public async Task ServerIsOff_Timeout()
        {
            int timeout = 1000; // 1s
            IIpcClient <ITestService> client = _factory
                                               .CreateClient((name, services) =>
            {
                services.AddNamedPipeIpcClient <ITestService>(name, (_, options) =>
                {
                    options.PipeName          = "inexisted-pipe";
                    options.ConnectionTimeout = timeout;
                });
            });

#if !DISABLE_DYNAMIC_CODE_GENERATION
            var sw = Stopwatch.StartNew();
            await Assert.ThrowsAsync <TimeoutException>(async() =>
            {
                string output = await client.InvokeAsync(x => x.StringType("abc"));
            });

            Assert.True(sw.ElapsedMilliseconds < timeout * 2); // makesure timeout works with marge
#endif

            var sw2 = Stopwatch.StartNew();
            await Assert.ThrowsAsync <TimeoutException>(async() =>
            {
                var request   = TestHelpers.CreateIpcRequest(typeof(ITestService), "StringType", false, new object[] { "abc" });
                string output = await client.InvokeAsync <string>(request);
            });

            Assert.True(sw2.ElapsedMilliseconds < timeout * 2); // makesure timeout works with marge
        }
Exemple #2
0
        public async Task ServerIsOff_Timeout()
        {
            int timeout = 1000; // 1s
            IIpcClient <ITestService> client = _factory
                                               .CreateClient((name, services) =>
            {
                services.AddNamedPipeIpcClient <ITestService>(name, (_, options) =>
                {
                    options.PipeName          = "inexisted-pipe";
                    options.ConnectionTimeout = timeout;
                });
            });

            var sw = Stopwatch.StartNew();
            await Assert.ThrowsAsync <TimeoutException>(async() =>
            {
                string output = await client.InvokeAsync(x => x.StringType("abc"));
            });

            Assert.True(sw.ElapsedMilliseconds < timeout * 2); // makesure timeout works with marge
        }
Exemple #3
0
        public async Task ConnectionTimeout_Throw()
        {
            int timeout = 3000; // 3s
            IIpcClient <ITestService> client = _factory
                                               .CreateClient((name, services) =>
            {
                services.AddTcpIpcClient <ITestService>(name, (_, options) =>
                {
                    // Connect to a non-routable IP address can trigger timeout
                    options.ServerIp          = IPAddress.Parse("10.0.0.0");
                    options.ConnectionTimeout = timeout;
                });
            });

            var sw = Stopwatch.StartNew();
            await Assert.ThrowsAsync <TimeoutException>(async() =>
            {
                string output = await client.InvokeAsync(x => x.StringType("abc"));
            });

            Assert.True(sw.ElapsedMilliseconds < timeout * 2); // makesure timeout works with marge
        }