Skip to content

Commit 4bf9494

Browse files
use async test assertions
1 parent 36f2e0b commit 4bf9494

4 files changed

Lines changed: 37 additions & 16 deletions

File tree

.github/workflows/test.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,21 @@ jobs:
5050
dotnet-version: 9.0.x
5151

5252
- uses: docker/setup-compose-action@v1
53-
- uses: hoverkraft-tech/compose-action@3846bcd61da338e9eaaf83e7ed0234a12b099b72
54-
with:
55-
compose-file: './Samples/Streaming/docker-compose.yaml'
56-
53+
54+
- name: Docker Compose Build
5755
env:
5856
NUGET_USERNAME: ${{ github.actor }}
5957
NUGET_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
58+
run: |
59+
docker compose up --build -d
60+
working-directory: ./Samples/Streaming
6061

6162
- name: Execute E2E Tests
6263
run: |
6364
dotnet restore Samples/Streaming/TestRunner/TestRunner.csproj
6465
dotnet test Samples/Streaming/TestRunner/TestRunner.csproj
6566
66-
- name: Cleanup
67-
run: |
68-
docker-compose down -v
67+
# - name: Cleanup
68+
# run: |
69+
# docker-compose down -v
6970

Samples/Streaming/TestRunner/EndToEndTest.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using System.Text.Json;
1+
using System.Net.Http.Json;
22
using System.Text.Json.Serialization;
33
using DataPlane.Sdk.Core.Domain.Model;
4+
using Polly;
5+
using Polly.Wrap;
46
using Shouldly;
57

68
namespace TestRunner;
@@ -10,6 +12,10 @@ public class EndToEndTest
1012
private const string ConsumerHost = "http://localhost:8081";
1113
private const string ProviderHost = "http://localhost:8080";
1214
private const string ParticipantId = "dataplane-signaling-api";
15+
private const string KeycloakHost = "http://localhost:8088";
16+
17+
18+
private readonly AsyncPolicyWrap _pollyRetry;
1319

1420
private readonly ControlPlaneSimulator _sim = new()
1521
{
@@ -19,18 +25,25 @@ public class EndToEndTest
1925
ProviderParticipant = ParticipantId // same participant id for both for the sake of simplicity
2026
};
2127

22-
// same participant id for both for the sake of simplicity
28+
public EndToEndTest()
29+
{
30+
var timeout = Policy.TimeoutAsync(TimeSpan.FromSeconds(5));
31+
var retry = Policy.Handle<Exception>().WaitAndRetryForeverAsync(_ => TimeSpan.FromMilliseconds(500));
32+
_pollyRetry = Policy.WrapAsync(timeout, retry);
33+
}
34+
2335

2436
[Fact]
2537
public async Task StreamingTest()
2638
{
27-
var accessToken = await ObtainAccessToken("dataplane-signaling-api", "mpoTntIrYjsBqhqo0xuzqRUtCWQCWjG3");
28-
accessToken.ShouldNotBeNull();
39+
var accessToken = await _pollyRetry
40+
.ExecuteAsync(async () => await ObtainAccessToken("dataplane-signaling-api", "mpoTntIrYjsBqhqo0xuzqRUtCWQCWjG3"));
2941

30-
var client = new HttpClient();
42+
accessToken.ShouldNotBeNull();
3143

3244
// prepare consumer
3345
var flowId = await _sim.PrepareConsumer(accessToken);
46+
await Task.Delay(1000);
3447

3548
// start provider
3649
var msg = await _sim.StartProvider(accessToken, flowId);
@@ -40,12 +53,14 @@ public async Task StreamingTest()
4053
msg.DataAddress.Properties.ShouldContainKey("endpointProperties");
4154

4255
var providerDa = msg.DataAddress;
56+
await Task.Delay(1000);
4357

4458
// notify consumer started
4559
var response = await _sim.NotifyConsumerStarted(accessToken, providerDa, flowId);
4660
response.ShouldNotBeNull();
4761
response.DataAddress.ShouldNotBeNull();
4862
response.State.ShouldBeEquivalentTo(DataFlowState.Started);
63+
await Task.Delay(1000);
4964

5065
//terminate provider
5166
await _sim.TerminateProvider(accessToken, flowId);
@@ -54,7 +69,7 @@ public async Task StreamingTest()
5469
private async Task<string> ObtainAccessToken(string clientId, string clientSecret)
5570
{
5671
var client = new HttpClient();
57-
client.BaseAddress = new Uri("http://localhost:8088");
72+
client.BaseAddress = new Uri(KeycloakHost);
5873
var entries = new List<KeyValuePair<string, string>>
5974
{
6075
new("grant_type", "client_credentials"),
@@ -64,9 +79,7 @@ private async Task<string> ObtainAccessToken(string clientId, string clientSecre
6479
};
6580
var result = await client.PostAsync("/realms/dataplane-signaling-api/protocol/openid-connect/token", new FormUrlEncodedContent(entries));
6681

67-
var at = await JsonSerializer.DeserializeAsync<AccessTokenResponse>(await result.Content.ReadAsStreamAsync());
68-
69-
82+
var at = await result.Content.ReadFromJsonAsync<AccessTokenResponse>();
7083
return at != null ? at.AccessToken : throw new Exception("Failed to obtain access token");
7184
}
7285

Samples/Streaming/TestRunner/TestRunner.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<PackageReference Include="Testcontainers.PostgreSql" Version="4.6.0"/>
1818
<PackageReference Include="xunit" Version="2.9.2"/>
1919
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>
20+
<PackageReference Include="Polly" Version="8.6.4"/>
2021
</ItemGroup>
2122

2223
<ItemGroup>

Samples/Streaming/docker-compose.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ services:
6868
- sample-network
6969
volumes:
7070
- ./Resources/Keycloak/dataplane-api-realm.json:/opt/keycloak/data/import/realm-export.json
71+
healthcheck:
72+
test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8088/health" ]
73+
interval: 10s
74+
timeout: 5s
75+
retries: 3
76+
start_period: 30s
7177

7278
nats:
7379
image: nats:latest

0 commit comments

Comments
 (0)