11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
4+ using Aspire . Hosting ;
45using Aspire . Hosting . Tests . Utils ;
56using SamplesIntegrationTests ;
67using SamplesIntegrationTests . Infrastructure ;
78using Xunit ;
9+ using Xunit . Sdk ;
810using Xunit . Abstractions ;
911
1012namespace Aspire . Playground . Tests ;
@@ -21,10 +23,59 @@ public async Task WithDockerfileTest()
2123 await app . StartAsync ( ) ;
2224 await app . WaitForResources ( ) . WaitAsync ( TimeSpan . FromMinutes ( 2 ) ) ;
2325
24- await app . WaitForTextAsync ( [ $ "I'm Batman. - Batman", "I am Iron Man. - Iron Man" ] )
26+ await app . WaitForTextAsync ( $ "I'm Batman. - Batman")
2527 . WaitAsync ( TimeSpan . FromMinutes ( 3 ) ) ;
2628
2729 app . EnsureNoErrorsLogged ( ) ;
2830 await app . StopAsync ( ) ;
2931 }
32+
33+ [ Fact ]
34+ public async Task KafkaTest ( )
35+ {
36+ var appHostPath = Directory . GetFiles ( AppContext . BaseDirectory , "KafkaBasic.AppHost.dll" ) . Single ( ) ;
37+ var appHost = await DistributedApplicationTestFactory . CreateAsync ( appHostPath , _testOutput ) ;
38+ await using var app = await appHost . BuildAsync ( ) ;
39+
40+ await app . StartAsync ( ) ;
41+ await app . WaitForResources ( ) . WaitAsync ( TimeSpan . FromMinutes ( 2 ) ) ;
42+
43+ await WaitForAllTextAsync ( app ,
44+ [
45+ "Hello, World! 343" ,
46+ "Received 1000 messges."
47+ ] ,
48+ timeoutSecs : 30 ) ;
49+
50+ app . EnsureNoErrorsLogged ( ) ;
51+ await app . StopAsync ( ) ;
52+ }
53+
54+ internal static async Task WaitForAllTextAsync ( DistributedApplication app , IEnumerable < string > logTexts , string ? resourceName = null , int timeoutSecs = - 1 )
55+ {
56+ var table = logTexts . ToList ( ) ;
57+ try
58+ {
59+ var task = app . WaitForTextAsync ( ( log ) =>
60+ {
61+ foreach ( var text in table )
62+ {
63+ if ( log . Contains ( text ) )
64+ {
65+ table . Remove ( text ) ;
66+ }
67+ }
68+
69+ return table . Count == 0 ;
70+ } , resourceName ) ;
71+
72+ await ( timeoutSecs > 0
73+ ? task . WaitAsync ( TimeSpan . FromSeconds ( timeoutSecs ) )
74+ : task ) ;
75+ }
76+ catch ( TimeoutException te )
77+ {
78+ throw new XunitException ( $ "The following messages were not found: { string . Join ( "', '" , table ) } ", te ) ;
79+ }
80+ }
3081}
0 commit comments