Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Jun 28, 2024
1 parent 4928f41 commit b869d36
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 49 deletions.
41 changes: 17 additions & 24 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@
name: Build and Test

on:
pull_request:
pull_request:

env:
TEST_RESULTS_PATH: ${{ github.workspace }}/test-results.trx

permissions:
contents: read
actions: read
checks: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4.1.7
- name: Setup .NET
uses: actions/setup-dotnet@v4.0.0
- uses: actions/checkout@v4.1.7
- uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: 8.0.100
- name: Dotnet Build
run: dotnet build --configuration Release
- name: Dotnet Test
run: |
dotnet test --configuration Release --no-restore --no-build --logger "trx;LogFileName=${{ env.TEST_RESULTS_PATH }}"
- name: Upload test results
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: test-results
path: ${{ env.TEST_RESULTS_PATH }}
- name: Upload test results
uses: dorny/test-reporter@v1.9.1
if: success() || failure()
- run: echo "${{ secrets.SNK_FILE }}" | base64 --decode > private.snk
- run: |
dotnet build \
--configuration Release \
-p:TreatWarningsAsErrors=true \
-p:TreatWarningsAsErrors=true \
-p:AssemblyOriginatorKeyFile=$(pwd)/private.snk
- run: |
dotnet test \
--configuration Release \
--no-restore \
--no-build \
--logger "trx;LogFileName=${{ env.TEST_RESULTS_PATH }}"
- uses: dorny/test-reporter@v1
with:
name: XUnit Tests
path: ${{ env.TEST_RESULTS_PATH }}
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/check-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Check Changelog

on:
pull_request:

jobs:
check-changelog:
runs-on: ubuntu-latest
steps:
- uses: tarides/changelog-check-action@v2
with:
changelog: CHANGES.md
18 changes: 18 additions & 0 deletions .github/workflows/publish-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Publish Test

on:
pull_request:

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.7
- uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: 8.0.100
- run: echo "${{ secrets.SNK_FILE }}" | base64 --decode > private.snk
- run: |
dotnet publish \
-p:TreatWarningsAsErrors=true \
-p:AssemblyOriginatorKeyFile=$(pwd)/private.snk
11 changes: 11 additions & 0 deletions .github/workflows/typos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Check Typos

on:
pull_request:

jobs:
typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: crate-ci/typos@v1.22.9
18 changes: 9 additions & 9 deletions src/JSSoft.Communication/Extensions/ISerializerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ public static string[] SerializeMany(this ISerializer @this, Type[] types, objec
return items;
}

public static object?[] DeserializeMany(this ISerializer @this, Type[] types, string[] datas)
public static object?[] DeserializeMany(this ISerializer @this, Type[] types, string[] data)
{
var items = new object?[datas.Length];
for (var i = 0; i < datas.Length; i++)
var items = new object?[data.Length];
for (var i = 0; i < data.Length; i++)
{
var type = types[i];
var value = datas[i];
var value = data[i];
items[i] = @this.Deserialize(type, value);
}

return items;
}

public static object?[] DeserializeMany(
this ISerializer @this, Type[] types, string[] datas, CancellationToken? cancellationToken)
this ISerializer @this, Type[] types, string[] data, CancellationToken? cancellationToken)
{
var length = cancellationToken != null ? datas.Length + 1 : datas.Length;
var length = cancellationToken != null ? data.Length + 1 : data.Length;
var items = new object?[length];
for (var i = 0; i < datas.Length; i++)
for (var i = 0; i < data.Length; i++)
{
var type = types[i];
var value = datas[i];
var value = data[i];
items[i] = @this.Deserialize(type, value);
}

if (cancellationToken != null)
{
items[datas.Length] = cancellationToken;
items[data.Length] = cancellationToken;
}

return items;
Expand Down
2 changes: 1 addition & 1 deletion src/JSSoft.Communication/Grpc/AdaptorServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public async Task<InvokeReply> InvokeAsync(InvokeRequest request, ServerCallCont
var instance = peer.Services[service];
var args = _serializer.DeserializeMany(
types: methodDescriptor.ParameterTypes,
datas: [.. request.Data],
data: [.. request.Data],
cancellationToken: cancellationToken);
if (methodDescriptor.IsOneWay == true)
{
Expand Down
2 changes: 1 addition & 1 deletion src/JSSoft.Communication/Grpc/Peer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void EndPolling()
}
}

public void Disconect(int closeCode)
public void Disconnect(int closeCode)
{
lock (_lockObject)
{
Expand Down
4 changes: 2 additions & 2 deletions src/JSSoft.Communication/Grpc/PeerCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public bool Remove(IServiceContext serviceContext, string id, int closeCode)
{
peer.Descriptor = null;
_instanceContext.DestroyInstance(peer);
peer.Disconect(closeCode);
peer.Disconnect(closeCode);
serviceContext.Debug($"{id} Disconnected ({closeCode})");
return true;
}
Expand All @@ -53,7 +53,7 @@ public async Task DisconnectAsync(
using var cancellationTokenSource = new CancellationTokenSource(millisecondsDelay: 3000);
foreach (var item in items)
{
item.Disconect(closeCode: 0);
item.Disconnect(closeCode: 0);
}

while (Count > 0 && cancellationTokenSource.IsCancellationRequested != true)
Expand Down
16 changes: 8 additions & 8 deletions src/JSSoft.Communication/MethodDescriptorCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace JSSoft.Communication;

public sealed class MethodDescriptorCollection : IEnumerable<MethodDescriptor>
{
private readonly Dictionary<string, MethodDescriptor> _discriptorByName;
private readonly Dictionary<string, MethodDescriptor> _descriptorByName;

internal MethodDescriptorCollection(Type type)
{
Expand All @@ -25,23 +25,23 @@ internal MethodDescriptorCollection(Type type)
{
var methodInfos = type.GetMethods();
var methodDescriptors = methodInfos.Select(item => new MethodDescriptor(item));
_discriptorByName = methodDescriptors.ToDictionary(item => item.Name);
_descriptorByName = methodDescriptors.ToDictionary(item => item.Name);
}
else
{
_discriptorByName = [];
_descriptorByName = [];
}
}

public int Count => _discriptorByName.Count;
public int Count => _descriptorByName.Count;

public MethodDescriptor this[string name] => _discriptorByName[name];
public MethodDescriptor this[string name] => _descriptorByName[name];

public bool Contains(string name) => _discriptorByName.ContainsKey(name);
public bool Contains(string name) => _descriptorByName.ContainsKey(name);

public IEnumerator<MethodDescriptor> GetEnumerator()
=> _discriptorByName.Values.GetEnumerator();
=> _descriptorByName.Values.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator()
=> _discriptorByName.Values.GetEnumerator();
=> _descriptorByName.Values.GetEnumerator();
}
8 changes: 4 additions & 4 deletions test/JSSoft.Communication.Tests/ClientTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public async Task DisposeAsync()
}
}

public abstract class ClientTestBase<TService, TServerSevice> : IAsyncLifetime
public abstract class ClientTestBase<TService, TServerService> : IAsyncLifetime
where TService : class
where TServerSevice : ServerService<TService>
where TServerService : ServerService<TService>
{
private readonly ClientService<TService> _clientService = new();
private readonly ServerContext _serverContext;
Expand All @@ -70,7 +70,7 @@ public abstract class ClientTestBase<TService, TServerSevice> : IAsyncLifetime
private Guid _clientToken;
private Guid _serverToken;

protected ClientTestBase(ITestOutputHelper logger, TServerSevice serverService)
protected ClientTestBase(ITestOutputHelper logger, TServerService serverService)
{
Logger = logger;
ServerService = serverService;
Expand All @@ -82,7 +82,7 @@ protected ClientTestBase(ITestOutputHelper logger, TServerSevice serverService)

protected TService Client => _client!;

protected TServerSevice ServerService { get; }
protected TServerService ServerService { get; }

public async Task InitializeAsync()
{
Expand Down

0 comments on commit b869d36

Please sign in to comment.