1 #region Copyright notice and license 2 3 // Copyright 2015 gRPC authors. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 #endregion 18 19 using System; 20 using System.Collections.Generic; 21 using System.Linq; 22 using System.Threading; 23 using System.Threading.Tasks; 24 using Grpc.Core; 25 using Grpc.Core.Utils; 26 using Grpc.Testing; 27 using NUnit.Framework; 28 29 namespace Grpc.IntegrationTesting 30 { 31 /// <summary> 32 /// Runs interop tests in-process. 33 /// </summary> 34 public class InteropClientServerTest 35 { 36 const string Host = "localhost"; 37 Server server; 38 Channel channel; 39 TestService.TestServiceClient client; 40 41 [OneTimeSetUp] Init()42 public void Init() 43 { 44 // Disable SO_REUSEPORT to prevent https://github.com/grpc/grpc/issues/10755 45 server = new Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) }) 46 { 47 Services = { TestService.BindService(new TestServiceImpl()) }, 48 Ports = { { Host, ServerPort.PickUnused, TestCredentials.CreateSslServerCredentials() } } 49 }; 50 server.Start(); 51 52 var options = new List<ChannelOption> 53 { 54 new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride) 55 }; 56 int port = server.Ports.Single().BoundPort; 57 channel = new Channel(Host, port, TestCredentials.CreateSslCredentials(), options); 58 client = new TestService.TestServiceClient(channel); 59 } 60 61 [OneTimeTearDown] Cleanup()62 public void Cleanup() 63 { 64 channel.ShutdownAsync().Wait(); 65 server.ShutdownAsync().Wait(); 66 } 67 68 [Test] EmptyUnary()69 public void EmptyUnary() 70 { 71 InteropClient.RunEmptyUnary(client); 72 } 73 74 [Test] LargeUnary()75 public void LargeUnary() 76 { 77 InteropClient.RunLargeUnary(client); 78 } 79 80 [Test] ClientStreaming()81 public async Task ClientStreaming() 82 { 83 await InteropClient.RunClientStreamingAsync(client); 84 } 85 86 [Test] ServerStreaming()87 public async Task ServerStreaming() 88 { 89 await InteropClient.RunServerStreamingAsync(client); 90 } 91 92 [Test] PingPong()93 public async Task PingPong() 94 { 95 await InteropClient.RunPingPongAsync(client); 96 } 97 98 [Test] EmptyStream()99 public async Task EmptyStream() 100 { 101 await InteropClient.RunEmptyStreamAsync(client); 102 } 103 104 [Test] CancelAfterBegin()105 public async Task CancelAfterBegin() 106 { 107 await InteropClient.RunCancelAfterBeginAsync(client); 108 } 109 110 [Test] CancelAfterFirstResponse()111 public async Task CancelAfterFirstResponse() 112 { 113 await InteropClient.RunCancelAfterFirstResponseAsync(client); 114 } 115 116 [Test] TimeoutOnSleepingServer()117 public async Task TimeoutOnSleepingServer() 118 { 119 await InteropClient.RunTimeoutOnSleepingServerAsync(client); 120 } 121 122 [Test] CustomMetadata()123 public async Task CustomMetadata() 124 { 125 await InteropClient.RunCustomMetadataAsync(client); 126 } 127 128 [Test] StatusCodeAndMessage()129 public async Task StatusCodeAndMessage() 130 { 131 await InteropClient.RunStatusCodeAndMessageAsync(client); 132 } 133 134 [Test] UnimplementedService()135 public void UnimplementedService() 136 { 137 InteropClient.RunUnimplementedService(new UnimplementedService.UnimplementedServiceClient(channel)); 138 } 139 140 [Test] UnimplementedMethod()141 public void UnimplementedMethod() 142 { 143 InteropClient.RunUnimplementedMethod(client); 144 } 145 } 146 } 147