diff --git a/src/JSSoft.Communication/Grpc/AdaptorClient.cs b/src/JSSoft.Communication/Grpc/AdaptorClient.cs index 31acaea..9de71e1 100644 --- a/src/JSSoft.Communication/Grpc/AdaptorClient.cs +++ b/src/JSSoft.Communication/Grpc/AdaptorClient.cs @@ -403,11 +403,6 @@ private void InvokeCallback(IService service, string name, string[] data) } var methodDescriptors = _methodsByService[service]; - if (methodDescriptors.Contains(name) != true) - { - throw new InvalidOperationException("Invalid method name."); - } - if (methodDescriptors.Contains(name) == true) { var methodDescriptor = methodDescriptors[name]; diff --git a/test/JSSoft.Communication.Tests/CallbackNoneTest.cs b/test/JSSoft.Communication.Tests/CallbackNoneTest.cs new file mode 100644 index 0000000..b51c18b --- /dev/null +++ b/test/JSSoft.Communication.Tests/CallbackNoneTest.cs @@ -0,0 +1,83 @@ +// +// Copyright (c) 2024 Jeesu Choi. All Rights Reserved. +// Licensed under the MIT License. See LICENSE.md in the project root for license information. +// + +using JSSoft.Communication.Tests.Extensions; +using Xunit.Abstractions; + +namespace JSSoft.Communication.Tests; + +public class CallbackNoneTest : IAsyncLifetime +{ + private const int Timeout = 30000; + private readonly ITestOutputHelper _logger; + private readonly TestServer1 _testServer = new(); + private readonly ServerContext _serverContext; + private readonly ClientContext _clientContext; + private readonly RandomEndPoint _endPoint = new(); + private ITestService1? _server; + + private Guid _clientToken; + private Guid _serverToken; + + public CallbackNoneTest(ITestOutputHelper logger) + { + _logger = logger; + _serverContext = new(_testServer) { EndPoint = _endPoint }; + _clientContext = new(new ClientService()) { EndPoint = _endPoint }; + logger.WriteLine($"{_endPoint}"); + } + + public interface ITestService1 + { + void Invoke(); + } + + public interface ITestService2 + { + void Invoke(); + } + + public interface ITestCallback2 + { + void OnInvoked(); + } + + [Fact] + public void Callback1_Test() + { + var manualResetEvent = new ManualResetEvent(false); + _clientContext.Disconnected += ClientContext_Disconnected; + _server!.Invoke(); + Assert.True(manualResetEvent.WaitOne(Timeout)); + + void ClientContext_Disconnected(object? sender, EventArgs e) + { + manualResetEvent.Set(); + } + } + + public async Task InitializeAsync() + { + _logger.WriteLine($"InitializeAsync 1"); + _serverToken = await _serverContext.OpenAsync(CancellationToken.None); + _clientToken = await _clientContext.OpenAsync(CancellationToken.None); + _server = _testServer; + _logger.WriteLine($"InitializeAsync 2"); + } + + public async Task DisposeAsync() + { + _logger.WriteLine($"DisposeAsync 1"); + await _serverContext.ReleaseAsync(_serverToken); + await _clientContext.ReleaseAsync(_clientToken); + _endPoint.Dispose(); + _logger.WriteLine($"DisposeAsync 2"); + } + + private sealed class TestServer1 : ServerService, ITestService1 + { + public void Invoke() => Client.OnInvoked(); + } +}