InteropClientServerTest.cs 4.2 KB

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