1- using System . Text . Json ;
1+ using System . Net . Http . Json ;
22using System . Text . Json . Serialization ;
33using DataPlane . Sdk . Core . Domain . Model ;
4+ using Polly ;
5+ using Polly . Wrap ;
46using Shouldly ;
57
68namespace 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
0 commit comments