Skip to content

Commit

Permalink
Tests,GrpcClient,GrpcServer: made e2e GRPC test
Browse files Browse the repository at this point in the history
Made end-to-end GRPC test that makes sure GRPC communication is
working.
  • Loading branch information
webwarrior-ws committed Feb 8, 2024
1 parent 94a7801 commit 2ee88ec
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/FX.GrpcClient/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ public class Instance
private static string serverFqdn =
"localhost";

public static readonly int Port = 5178;
public static readonly int HttpsPort = 7178;

public FXGrpcService.FXGrpcServiceClient Connect()
{
var channel = GrpcChannel.ForAddress($"http://{serverFqdn}:8080");
var channel = GrpcChannel.ForAddress($"http://{serverFqdn}:{Port}");
var client = new FXGrpcService.FXGrpcServiceClient(channel);
return client;
}
Expand All @@ -23,9 +26,10 @@ public async Task<string> SendMessage(string message)
{
var client = Connect();
var reply = await client.GenericMethodAsync(
new GenericInputParam { MsgIn = "hello" }
new GenericInputParam { MsgIn = message }
);
Console.WriteLine($"Got response: {reply.MsgOut}");
return reply.MsgOut;
}
}
}
2 changes: 1 addition & 1 deletion src/FX.GrpcService/Services/FXService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override async Task GenericStreamOutputMethod(GenericInputParam request,
{
Console.WriteLine(request.MsgIn);

await responseStream.WriteAsync(new GenericOutputParam { MsgOut = "ack" });
await responseStream.WriteAsync(new GenericOutputParam { MsgOut = "received " + request.MsgIn });
}
}
}
56 changes: 56 additions & 0 deletions src/FX.Tests/E2ETests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using FsharpExchangeDotNetStandard;

using NUnit.Framework;
using StackExchange.Redis;

namespace FsharpExchange.Tests
{
[TestFixture]
public class E2ETests
{
private Process LaunchGrpcServer()
{
var solutionDir = (new DirectoryInfo(Environment.CurrentDirectory)).Parent?.Parent?.Parent?.Parent?.Parent;
var serviceExeDir = Path.Join(solutionDir.FullName, "src", "FX.GrpcService", "bin", "Debug", "net8.0");

var argsString = $"--urls http://localhost:{GrpcClient.Instance.Port}";

if (OperatingSystem.IsWindows())
{
var serviceExePath = Path.Join(serviceExeDir, "FX.GrpcService.exe");
return Process.Start(serviceExePath, argsString);
}
else
{
var processInfo = new ProcessStartInfo
{
UseShellExecute = false,
CreateNoWindow = true,
FileName = "dotnet",
Arguments = Path.Join(serviceExeDir, "FX.GrpcService.dll") + " " + argsString
};
return Process.Start(processInfo);
}
}

[Test]
async public Task GrpcE2ETest()
{
using var serverProcess = LaunchGrpcServer();
await Task.Delay(TimeSpan.FromSeconds(1.0));

var client = new GrpcClient.Instance();
client.Connect();

var message = "hello";
var response = await client.SendMessage(message);

Assert.That(response, Is.EqualTo("received " + message));
}
}
}
1 change: 1 addition & 0 deletions src/FX.Tests/FX.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FX.Core\FX.Core.fsproj" />
<ProjectReference Include="..\FX.GrpcClient\FX.GrpcClient.csproj" />
</ItemGroup>
</Project>

0 comments on commit 2ee88ec

Please sign in to comment.