blob: 837ae74c453db8bfa4c1ad921180c019a5872b3d [file] [log] [blame]
Jan Tattermusch20831382015-02-24 14:16:04 -08001#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
34using System;
35using System.Collections.Generic;
Jan Tattermusch31ba0632015-08-04 22:02:55 -070036using System.Linq;
Jan Tattermusch20831382015-02-24 14:16:04 -080037using System.Threading;
38using System.Threading.Tasks;
39using Grpc.Core;
40using Grpc.Core.Utils;
Jan Tattermusch8644aea2015-08-03 10:21:18 -070041using Grpc.Testing;
Jan Tattermusch20831382015-02-24 14:16:04 -080042using NUnit.Framework;
Jan Tattermusch20831382015-02-24 14:16:04 -080043
44namespace Grpc.IntegrationTesting
45{
46 /// <summary>
47 /// Runs interop tests in-process.
48 /// </summary>
49 public class InteropClientServerTest
50 {
Jan Tattermusch31ba0632015-08-04 22:02:55 -070051 const string Host = "localhost";
Jan Tattermusch20831382015-02-24 14:16:04 -080052 Server server;
53 Channel channel;
Jan Tattermusch7eb3a762015-05-07 14:26:13 -070054 TestService.ITestServiceClient client;
Jan Tattermusch20831382015-02-24 14:16:04 -080055
56 [TestFixtureSetUp]
57 public void Init()
58 {
Jan Tattermusch31ba0632015-08-04 22:02:55 -070059 server = new Server
Jan Tattermusch021df8a2015-08-04 20:31:11 -070060 {
Jan Tattermusch31ba0632015-08-04 22:02:55 -070061 Services = { TestService.BindService(new TestServiceImpl()) },
Jan Tattermuschbeffc772015-10-22 13:28:22 -070062 Ports = { { Host, ServerPort.PickUnused, TestCredentials.CreateSslServerCredentials() } }
Jan Tattermusch021df8a2015-08-04 20:31:11 -070063 };
Jan Tattermusch20831382015-02-24 14:16:04 -080064 server.Start();
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080065
Jan Tattermuschc8f7d102015-06-08 17:53:45 -070066 var options = new List<ChannelOption>
67 {
Jan Tattermusch2ddb5a62015-06-08 17:51:36 -070068 new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
69 };
Jan Tattermusch31ba0632015-08-04 22:02:55 -070070 int port = server.Ports.Single().BoundPort;
Jan Tattermuschbeffc772015-10-22 13:28:22 -070071 channel = new Channel(Host, port, TestCredentials.CreateSslCredentials(), options);
Jan Tattermuschb5332812015-07-14 19:29:35 -070072 client = TestService.NewClient(channel);
Jan Tattermusch20831382015-02-24 14:16:04 -080073 }
74
75 [TestFixtureTearDown]
76 public void Cleanup()
77 {
Jan Tattermusch2b357952015-08-20 14:54:33 -070078 channel.ShutdownAsync().Wait();
Jan Tattermusch20831382015-02-24 14:16:04 -080079 server.ShutdownAsync().Wait();
Jan Tattermusch20831382015-02-24 14:16:04 -080080 }
81
82 [Test]
83 public void EmptyUnary()
84 {
Jan Tattermusch503bbac2015-02-26 18:19:47 -080085 InteropClient.RunEmptyUnary(client);
Jan Tattermusch20831382015-02-24 14:16:04 -080086 }
87
88 [Test]
89 public void LargeUnary()
90 {
Jan Tattermuscha5272b62015-04-30 11:56:46 -070091 InteropClient.RunLargeUnary(client);
Jan Tattermusch20831382015-02-24 14:16:04 -080092 }
93
94 [Test]
Jan Tattermuschb98e1dd2015-07-24 21:30:14 -070095 public async Task ClientStreaming()
Jan Tattermusch20831382015-02-24 14:16:04 -080096 {
Jan Tattermuschb98e1dd2015-07-24 21:30:14 -070097 await InteropClient.RunClientStreamingAsync(client);
Jan Tattermusch20831382015-02-24 14:16:04 -080098 }
99
100 [Test]
Jan Tattermuschb98e1dd2015-07-24 21:30:14 -0700101 public async Task ServerStreaming()
Jan Tattermusch20831382015-02-24 14:16:04 -0800102 {
Jan Tattermuschb98e1dd2015-07-24 21:30:14 -0700103 await InteropClient.RunServerStreamingAsync(client);
Jan Tattermusch20831382015-02-24 14:16:04 -0800104 }
105
106 [Test]
Jan Tattermuschb98e1dd2015-07-24 21:30:14 -0700107 public async Task PingPong()
Jan Tattermusch20831382015-02-24 14:16:04 -0800108 {
Jan Tattermuschb98e1dd2015-07-24 21:30:14 -0700109 await InteropClient.RunPingPongAsync(client);
Jan Tattermusch20831382015-02-24 14:16:04 -0800110 }
111
112 [Test]
Jan Tattermuschb98e1dd2015-07-24 21:30:14 -0700113 public async Task EmptyStream()
Jan Tattermusch20831382015-02-24 14:16:04 -0800114 {
Jan Tattermuschb98e1dd2015-07-24 21:30:14 -0700115 await InteropClient.RunEmptyStreamAsync(client);
Jan Tattermusch20831382015-02-24 14:16:04 -0800116 }
117
Jan Tattermusche5c44602015-05-01 11:12:34 -0700118 [Test]
Jan Tattermuschb98e1dd2015-07-24 21:30:14 -0700119 public async Task CancelAfterBegin()
Jan Tattermusche5c44602015-05-01 11:12:34 -0700120 {
Jan Tattermuschb98e1dd2015-07-24 21:30:14 -0700121 await InteropClient.RunCancelAfterBeginAsync(client);
Jan Tattermusche5c44602015-05-01 11:12:34 -0700122 }
Jan Tattermusch20831382015-02-24 14:16:04 -0800123
Jan Tattermusche5c44602015-05-01 11:12:34 -0700124 [Test]
Jan Tattermuschb98e1dd2015-07-24 21:30:14 -0700125 public async Task CancelAfterFirstResponse()
Jan Tattermusche5c44602015-05-01 11:12:34 -0700126 {
Jan Tattermuschb98e1dd2015-07-24 21:30:14 -0700127 await InteropClient.RunCancelAfterFirstResponseAsync(client);
Jan Tattermusche5c44602015-05-01 11:12:34 -0700128 }
Jan Tattermusche4134dd2015-08-12 14:54:40 -0700129
130 [Test]
131 public async Task TimeoutOnSleepingServerAsync()
132 {
133 await InteropClient.RunTimeoutOnSleepingServerAsync(client);
134 }
Jan Tattermusch20831382015-02-24 14:16:04 -0800135 }
136}