Skip to content

Commit

Permalink
Merge branch 'madu/update-nuget-packages-mid-week' of https://github.…
Browse files Browse the repository at this point in the history
…com/Energinet-DataHub/opengeh-edi into madu/update-nuget-packages-mid-week
  • Loading branch information
MadsDue committed Nov 18, 2024
2 parents 966bb91 + 5c1192c commit 5dee9d1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
15 changes: 15 additions & 0 deletions source/SubsystemTests/Drivers/EdiDatabaseDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,21 @@ WHERE B.DequeuedAt IS NOT NULL
return dequeuedMessagesCount;
}

internal async Task<int> CountEnqueuedMessagesForCalculationAsync(Guid calculationId)
{
await using var connection = new SqlConnection(_connectionString);

await connection.OpenAsync();

var enqueuedMessagesCount = await connection.ExecuteScalarAsync<int>(
sql: @"SELECT COUNT(B.[Id]) FROM [Bundles] B
INNER JOIN [OutgoingMessages] OM ON B.[Id] = OM.[AssignedBundleId]
WHERE OM.[CalculationId] = @CalculationId",
param: new { CalculationId = calculationId, });

return enqueuedMessagesCount;
}

private async Task<Guid?> GetProcessIdAsync(SqlCommand command, CancellationToken cancellationToken)
{
await using var connection = new SqlConnection(_connectionString);
Expand Down
16 changes: 16 additions & 0 deletions source/SubsystemTests/LoadTest/LoadTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using Energinet.DataHub.Core.FunctionApp.TestCommon.Configuration;
using Energinet.DataHub.EDI.B2BApi.AppTests.DurableTask;
using Energinet.DataHub.EDI.SubsystemTests.Drivers;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Extensions.Configuration;

Expand Down Expand Up @@ -61,6 +63,11 @@ public LoadTestFixture()
configuration,
"LOAD_TEST_CALCULATION_ID");

MinimumEnqueuedMessagesCount = GetConfigurationValue<int>(
configuration,
"MINIMUM_ENQUEUED_MESSAGES_COUNT",
defaultValue: 0);

MinimumDequeuedMessagesCount = GetConfigurationValue<int>(
configuration,
"MINIMUM_DEQUEUED_MESSAGES_COUNT",
Expand All @@ -73,18 +80,27 @@ public LoadTestFixture()
_durableTaskManager = new DurableTaskManager(
"OrchestrationsStorageConnectionString",
GetConfigurationValue<string>(configuration, "func-edi-api-taskhub-storage-connection-string"));

var credential = new DefaultAzureCredential();
var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
telemetryConfiguration.SetAzureTokenCredential(credential);
TelemetryClient = new TelemetryClient(telemetryConfiguration);
}

internal EdiInboxClient EdiInboxClient { get; }

internal Guid LoadTestCalculationId { get; }

internal int MinimumEnqueuedMessagesCount { get; }

internal int MinimumDequeuedMessagesCount { get; }

internal IntegrationEventPublisher IntegrationEventPublisher { get; }

internal string DatabaseConnectionString { get; }

internal TelemetryClient TelemetryClient { get; }

[NotNull]
internal IDurableClient? DurableClient { get; private set; }

Expand Down
16 changes: 13 additions & 3 deletions source/SubsystemTests/LoadTest/LoadTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Energinet.DataHub.EDI.SubsystemTests.Drivers;
using Energinet.DataHub.EDI.SubsystemTests.Dsl;
using FluentAssertions;
using FluentAssertions.Execution;
using Nito.AsyncEx;
using NodaTime;
using Xunit.Abstractions;
Expand All @@ -35,6 +36,8 @@ namespace Energinet.DataHub.EDI.SubsystemTests.LoadTest;
[SuppressMessage("Style", "VSTHRD200:Use \"Async\" suffix for async methods", Justification = "Test class")]
public sealed class LoadTestHelper : IClassFixture<LoadTestFixture>
{
private const string EnqueuedAmountMetric = "EnqueuedAmount";
private const string DequeuedAmountMetric = "DequeuedAmount";
private readonly LoadTestFixture _fixture;
private readonly ITestOutputHelper _logger;
private readonly EdiDriver _ediDriver;
Expand Down Expand Up @@ -69,13 +72,20 @@ await CalculationCompletedDsl.StartEnqueueMessagesOrchestration(
[Fact]
public async Task After_load_test()
{
await _ediDriver.StopOrchestrationForCalculationAsync(
calculationId: _fixture.LoadTestCalculationId,
createdAfter: SystemClock.Instance.GetCurrentInstant().Minus(Duration.FromHours(1)));
var enqueuedMessagesCount = await _ediDatabaseDriver.CountEnqueuedMessagesForCalculationAsync(_fixture.LoadTestCalculationId);
_logger.WriteLine($"Enqueued messages count: {enqueuedMessagesCount} (CalculationId={_fixture.LoadTestCalculationId})");

var dequeuedMessagesCount = await _ediDatabaseDriver.CountDequeuedMessagesForCalculationAsync(_fixture.LoadTestCalculationId);
_logger.WriteLine($"Dequeued messages count: {dequeuedMessagesCount} (CalculationId={_fixture.LoadTestCalculationId})");

_fixture.TelemetryClient.GetMetric(EnqueuedAmountMetric).TrackValue(enqueuedMessagesCount);
_fixture.TelemetryClient.GetMetric(DequeuedAmountMetric).TrackValue(dequeuedMessagesCount);

using var scope = new AssertionScope();
enqueuedMessagesCount.Should().BeGreaterThanOrEqualTo(
_fixture.MinimumEnqueuedMessagesCount,
$"because the system should be performant enough to enqueue at least {_fixture.MinimumEnqueuedMessagesCount} messages during the load test");

dequeuedMessagesCount.Should().BeGreaterThanOrEqualTo(
_fixture.MinimumDequeuedMessagesCount,
$"because the system should be performant enough to dequeue at least {_fixture.MinimumDequeuedMessagesCount} messages during the load test");
Expand Down

0 comments on commit 5dee9d1

Please sign in to comment.