Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add concurrent channel tests #514

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Tests

on:
pull_request:
push:
branches:
- main

concurrency:
group: test-${{ github.ref }}
Expand Down
28 changes: 28 additions & 0 deletions packages/csharp/ArmoniK.Api.Client.Test/ConnectivityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Linq;
using System.Threading.Tasks;

using ArmoniK.Api.gRPC.V1;
using ArmoniK.Api.gRPC.V1.Results;
using ArmoniK.Utils;

using NUnit.Framework;

Expand All @@ -40,4 +44,28 @@ public void ResultsGetServiceConfiguration([Values] ConnectivityKind connectivit
Assert.That(() => resultClient.GetServiceConfiguration(new Empty()),
Throws.Nothing);
}

[Test]
public async Task MultipleChannels([Values] ConnectivityKind connectivityKind,
[Values(1,
2,
10,
100)]
int concurrency)
{
var channels = await Enumerable.Range(0,
concurrency)
.ParallelSelect(new ParallelTaskOptions(-1),
i => Task.FromResult(connectivityKind.GetChannel()))
.ToListAsync()
.ConfigureAwait(false);

await channels.ParallelForEach(async channel =>
{
var resultClient = new Results.ResultsClient(channel);
await resultClient.GetServiceConfigurationAsync(new Empty())
.ConfigureAwait(false);
})
.ConfigureAwait(false);
}
}
16 changes: 10 additions & 6 deletions packages/csharp/ArmoniK.Api.Client/Submitter/GrpcChannelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
using System.Security.Authentication;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -280,7 +279,8 @@ private static GrpcChannel CreateChannelInternal(GrpcClient optionsGrpcClient,
var parser = new X509CertificateParser();
using var stream = File.Open(optionsGrpcClient.CaCert,
FileMode.Open,
FileAccess.Read);
FileAccess.Read,
FileShare.Read);
caCert = parser.ReadCertificate(stream);
}

Expand Down Expand Up @@ -449,16 +449,20 @@ public static X509Certificate2 GetCertificate(GrpcClient optionsGrpcClient)
X509Certificate cert;
using (var reader = new FileStream(optionsGrpcClient.CertPem,
FileMode.Open,
FileAccess.Read))
FileAccess.Read,
FileShare.Read))
{
cert = new X509CertificateParser().ReadCertificate(reader);
}

var store = new Pkcs12StoreBuilder().Build();
using (var reader = new StreamReader(optionsGrpcClient.KeyPem,
Encoding.UTF8))
using (var reader = new FileStream(optionsGrpcClient.KeyPem,
FileMode.Open,
FileAccess.Read,
FileShare.Read))
using (var textReader = new StreamReader(reader))
{
var pemReader = new PemReader(reader);
var pemReader = new PemReader(textReader);
AsymmetricKeyParameter? key;

do
Expand Down
Loading