blob: 3eaccf122b8fa3ab94fa46d1782d3d6be7071948 [file] [log] [blame]
Jan Tattermusch2b357952015-08-20 14:54:33 -07001#region Copyright notice and license
2
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003// Copyright 2015 gRPC authors.
Jan Tattermusch2b357952015-08-20 14:54:33 -07004//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005// 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
Jan Tattermusch2b357952015-08-20 14:54:33 -07008//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009// http://www.apache.org/licenses/LICENSE-2.0
Jan Tattermusch2b357952015-08-20 14:54:33 -070010//
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011// 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.
Jan Tattermusch2b357952015-08-20 14:54:33 -070016
17#endregion
18
19using System;
20using System.Diagnostics;
21using System.Linq;
22using System.Threading;
23using System.Threading.Tasks;
24using Grpc.Core;
25using Grpc.Core.Internal;
26using Grpc.Core.Utils;
27using NUnit.Framework;
28
29namespace Grpc.Core.Tests
30{
31 public class ShutdownTest
32 {
33 const string Host = "127.0.0.1";
34
35 MockServiceHelper helper;
36 Server server;
37 Channel channel;
38
39 [SetUp]
40 public void Init()
41 {
42 helper = new MockServiceHelper(Host);
43 server = helper.GetServer();
44 server.Start();
45 channel = helper.GetChannel();
46 }
47
48 [Test]
Jan Tattermuschd63b1d62015-12-11 10:39:57 -080049 public async Task AbandonedCall_ServerKillAsync()
Jan Tattermusch2b357952015-08-20 14:54:33 -070050 {
Jan Tattermuschd63b1d62015-12-11 10:39:57 -080051 var readyToShutdown = new TaskCompletionSource<object>();
Jan Tattermusch2b357952015-08-20 14:54:33 -070052 helper.DuplexStreamingHandler = new DuplexStreamingServerMethod<string, string>(async (requestStream, responseStream, context) =>
53 {
Jan Tattermuschd63b1d62015-12-11 10:39:57 -080054 readyToShutdown.SetResult(null);
Jan Tattermusch2b357952015-08-20 14:54:33 -070055 await requestStream.ToListAsync();
56 });
57
Jan Tattermuschd63b1d62015-12-11 10:39:57 -080058 var call = Calls.AsyncDuplexStreamingCall(helper.CreateDuplexStreamingCall());
59 await readyToShutdown.Task; // make sure handler is running
Jan Tattermusch2b357952015-08-20 14:54:33 -070060
Jan Tattermuschd63b1d62015-12-11 10:39:57 -080061 await channel.ShutdownAsync(); // channel.ShutdownAsync() works even if there's a pending call.
62 await server.KillAsync(); // server.ShutdownAsync() would hang waiting for the call to finish.
Jan Tattermusch2b357952015-08-20 14:54:33 -070063 }
64 }
65}