Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 1 | #region Copyright notice and license |
| 2 | |
| 3 | // Copyright 2015, Google Inc. |
| 4 | // All rights reserved. |
| 5 | // |
| 6 | // Redistribution and use in source and binary forms, with or without |
| 7 | // modification, are permitted provided that the following conditions are |
| 8 | // met: |
| 9 | // |
| 10 | // * Redistributions of source code must retain the above copyright |
| 11 | // notice, this list of conditions and the following disclaimer. |
| 12 | // * Redistributions in binary form must reproduce the above |
| 13 | // copyright notice, this list of conditions and the following disclaimer |
| 14 | // in the documentation and/or other materials provided with the |
| 15 | // distribution. |
| 16 | // * Neither the name of Google Inc. nor the names of its |
| 17 | // contributors may be used to endorse or promote products derived from |
| 18 | // this software without specific prior written permission. |
| 19 | // |
| 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | #endregion |
| 33 | |
| 34 | using System; |
| 35 | using System.Collections.Generic; |
Jan Tattermusch | 31ba063 | 2015-08-04 22:02:55 -0700 | [diff] [blame] | 36 | using System.Linq; |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 37 | using System.Threading; |
| 38 | using System.Threading.Tasks; |
| 39 | using Grpc.Core; |
| 40 | using Grpc.Core.Utils; |
Jan Tattermusch | 8644aea | 2015-08-03 10:21:18 -0700 | [diff] [blame] | 41 | using Grpc.Testing; |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 42 | using NUnit.Framework; |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 43 | |
| 44 | namespace Grpc.IntegrationTesting |
| 45 | { |
| 46 | /// <summary> |
| 47 | /// Runs interop tests in-process. |
| 48 | /// </summary> |
| 49 | public class InteropClientServerTest |
| 50 | { |
Jan Tattermusch | 31ba063 | 2015-08-04 22:02:55 -0700 | [diff] [blame] | 51 | const string Host = "localhost"; |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 52 | Server server; |
| 53 | Channel channel; |
Jan Tattermusch | 7eb3a76 | 2015-05-07 14:26:13 -0700 | [diff] [blame] | 54 | TestService.ITestServiceClient client; |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 55 | |
| 56 | [TestFixtureSetUp] |
| 57 | public void Init() |
| 58 | { |
Jan Tattermusch | 31ba063 | 2015-08-04 22:02:55 -0700 | [diff] [blame] | 59 | server = new Server |
Jan Tattermusch | 021df8a | 2015-08-04 20:31:11 -0700 | [diff] [blame] | 60 | { |
Jan Tattermusch | 31ba063 | 2015-08-04 22:02:55 -0700 | [diff] [blame] | 61 | Services = { TestService.BindService(new TestServiceImpl()) }, |
Jan Tattermusch | beffc77 | 2015-10-22 13:28:22 -0700 | [diff] [blame^] | 62 | Ports = { { Host, ServerPort.PickUnused, TestCredentials.CreateSslServerCredentials() } } |
Jan Tattermusch | 021df8a | 2015-08-04 20:31:11 -0700 | [diff] [blame] | 63 | }; |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 64 | server.Start(); |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 65 | |
Jan Tattermusch | c8f7d10 | 2015-06-08 17:53:45 -0700 | [diff] [blame] | 66 | var options = new List<ChannelOption> |
| 67 | { |
Jan Tattermusch | 2ddb5a6 | 2015-06-08 17:51:36 -0700 | [diff] [blame] | 68 | new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride) |
| 69 | }; |
Jan Tattermusch | 31ba063 | 2015-08-04 22:02:55 -0700 | [diff] [blame] | 70 | int port = server.Ports.Single().BoundPort; |
Jan Tattermusch | beffc77 | 2015-10-22 13:28:22 -0700 | [diff] [blame^] | 71 | channel = new Channel(Host, port, TestCredentials.CreateSslCredentials(), options); |
Jan Tattermusch | b533281 | 2015-07-14 19:29:35 -0700 | [diff] [blame] | 72 | client = TestService.NewClient(channel); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | [TestFixtureTearDown] |
| 76 | public void Cleanup() |
| 77 | { |
Jan Tattermusch | 2b35795 | 2015-08-20 14:54:33 -0700 | [diff] [blame] | 78 | channel.ShutdownAsync().Wait(); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 79 | server.ShutdownAsync().Wait(); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | [Test] |
| 83 | public void EmptyUnary() |
| 84 | { |
Jan Tattermusch | 503bbac | 2015-02-26 18:19:47 -0800 | [diff] [blame] | 85 | InteropClient.RunEmptyUnary(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | [Test] |
| 89 | public void LargeUnary() |
| 90 | { |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 91 | InteropClient.RunLargeUnary(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | [Test] |
Jan Tattermusch | b98e1dd | 2015-07-24 21:30:14 -0700 | [diff] [blame] | 95 | public async Task ClientStreaming() |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 96 | { |
Jan Tattermusch | b98e1dd | 2015-07-24 21:30:14 -0700 | [diff] [blame] | 97 | await InteropClient.RunClientStreamingAsync(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | [Test] |
Jan Tattermusch | b98e1dd | 2015-07-24 21:30:14 -0700 | [diff] [blame] | 101 | public async Task ServerStreaming() |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 102 | { |
Jan Tattermusch | b98e1dd | 2015-07-24 21:30:14 -0700 | [diff] [blame] | 103 | await InteropClient.RunServerStreamingAsync(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | [Test] |
Jan Tattermusch | b98e1dd | 2015-07-24 21:30:14 -0700 | [diff] [blame] | 107 | public async Task PingPong() |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 108 | { |
Jan Tattermusch | b98e1dd | 2015-07-24 21:30:14 -0700 | [diff] [blame] | 109 | await InteropClient.RunPingPongAsync(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | [Test] |
Jan Tattermusch | b98e1dd | 2015-07-24 21:30:14 -0700 | [diff] [blame] | 113 | public async Task EmptyStream() |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 114 | { |
Jan Tattermusch | b98e1dd | 2015-07-24 21:30:14 -0700 | [diff] [blame] | 115 | await InteropClient.RunEmptyStreamAsync(client); |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 118 | [Test] |
Jan Tattermusch | b98e1dd | 2015-07-24 21:30:14 -0700 | [diff] [blame] | 119 | public async Task CancelAfterBegin() |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 120 | { |
Jan Tattermusch | b98e1dd | 2015-07-24 21:30:14 -0700 | [diff] [blame] | 121 | await InteropClient.RunCancelAfterBeginAsync(client); |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 122 | } |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 123 | |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 124 | [Test] |
Jan Tattermusch | b98e1dd | 2015-07-24 21:30:14 -0700 | [diff] [blame] | 125 | public async Task CancelAfterFirstResponse() |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 126 | { |
Jan Tattermusch | b98e1dd | 2015-07-24 21:30:14 -0700 | [diff] [blame] | 127 | await InteropClient.RunCancelAfterFirstResponseAsync(client); |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 128 | } |
Jan Tattermusch | e4134dd | 2015-08-12 14:54:40 -0700 | [diff] [blame] | 129 | |
| 130 | [Test] |
| 131 | public async Task TimeoutOnSleepingServerAsync() |
| 132 | { |
| 133 | await InteropClient.RunTimeoutOnSleepingServerAsync(client); |
| 134 | } |
Jan Tattermusch | 2083138 | 2015-02-24 14:16:04 -0800 | [diff] [blame] | 135 | } |
| 136 | } |