ExternalDnsClientServerTest.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #region Copyright notice and license
  2. // Copyright 2019 The gRPC Authors.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Threading;
  20. using System.Threading.Tasks;
  21. using Grpc.Core;
  22. using Grpc.Core.Utils;
  23. using Grpc.Testing;
  24. using NUnit.Framework;
  25. namespace Grpc.IntegrationTesting
  26. {
  27. /// <summary>
  28. /// Runs interop tests in-process, with that client using a target
  29. /// name that using a target name that triggers interaction with
  30. /// external DNS servers (even though it resolves to the in-proc server).
  31. /// This test is a trimmed-down sibling test to the one in
  32. /// "ExternalDnsWithTracingClientServerTest", and is meant mostly for
  33. /// comparison with that one.
  34. /// </summary>
  35. public class ExternalDnsClientServerTest
  36. {
  37. Server server;
  38. Channel channel;
  39. TestService.TestServiceClient client;
  40. [OneTimeSetUp]
  41. public void Init()
  42. {
  43. // Disable SO_REUSEPORT to prevent https://github.com/grpc/grpc/issues/10755
  44. server = new Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) })
  45. {
  46. Services = { TestService.BindService(new TestServiceImpl()) },
  47. Ports = { { "[::1]", ServerPort.PickUnused, ServerCredentials.Insecure } }
  48. };
  49. server.Start();
  50. int port = server.Ports.Single().BoundPort;
  51. channel = new Channel("loopback6.unittest.grpc.io", port, ChannelCredentials.Insecure);
  52. client = new TestService.TestServiceClient(channel);
  53. }
  54. [OneTimeTearDown]
  55. public void Cleanup()
  56. {
  57. channel.ShutdownAsync().Wait();
  58. server.ShutdownAsync().Wait();
  59. }
  60. [Test]
  61. public void EmptyUnary()
  62. {
  63. InteropClient.RunEmptyUnary(client);
  64. }
  65. }
  66. }