Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Jun 15, 2024
1 parent fc44935 commit 1cd76f4
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/JSSoft.Communication/Grpc/AdaptorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
83 changes: 83 additions & 0 deletions test/JSSoft.Communication.Tests/CallbackNoneTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// <copyright file="CallbackNoneTest.cs" company="JSSoft">
// Copyright (c) 2024 Jeesu Choi. All Rights Reserved.
// Licensed under the MIT License. See LICENSE.md in the project root for license information.
// </copyright>

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<ITestService1>()) { 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));

Check failure on line 53 in test/JSSoft.Communication.Tests/CallbackNoneTest.cs

View workflow job for this annotation

GitHub Actions / XUnit Tests

JSSoft.Communication.Tests.CallbackNoneTest ► Callback1_Test

Failed test found in: /home/runner/work/communication/communication/logs/test-results.trx Error: Assert.True() Failure Expected: True Actual: False
Raw output
Assert.True() Failure
Expected: True
Actual:   False
   at JSSoft.Communication.Tests.CallbackNoneTest.Callback1_Test() in /home/runner/work/communication/communication/test/JSSoft.Communication.Tests/CallbackNoneTest.cs:line 53
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

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, ITestCallback2>, ITestService1
{
public void Invoke() => Client.OnInvoked();
}
}

0 comments on commit 1cd76f4

Please sign in to comment.