@@ -8,7 +8,7 @@ public sealed class CosmosDbBuilder : ContainerBuilder<CosmosDbBuilder, CosmosDb
88 public const string CosmosDbImage = "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview" ;
99
1010 public const ushort CosmosDbPort = 8081 ;
11- public const ushort CosmosDbHealthCheckPort = 8080 ;
11+
1212 public const string DefaultAccountKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" ;
1313
1414 /// <summary>
@@ -77,10 +77,10 @@ protected override CosmosDbBuilder Init()
7777 {
7878 return base . Init ( )
7979 . WithPortBinding ( CosmosDbPort , true )
80- . WithPortBinding ( CosmosDbHealthCheckPort , true )
8180 . WithEnvironment ( "ENABLE_EXPLORER" , "false" )
81+ . WithEnvironment ( "ENABLE_TELEMETRY" , "false" )
8282 . WithConnectionStringProvider ( new CosmosDbConnectionStringProvider ( ) )
83- . WithWaitStrategy ( Wait . ForUnixContainer ( ) . AddCustomWaitStrategy ( new WaitUntil ( ) ) ) ;
83+ . WithWaitStrategy ( Wait . ForUnixContainer ( ) . UntilMessageIsLogged ( "Started" ) ) ;
8484 }
8585
8686 /// <inheritdoc />
@@ -100,68 +100,4 @@ protected override CosmosDbBuilder Merge(CosmosDbConfiguration oldValue, CosmosD
100100 {
101101 return new CosmosDbBuilder ( new CosmosDbConfiguration ( oldValue , newValue ) ) ;
102102 }
103-
104- /// <inheritdoc cref="IWaitUntil" />
105- private sealed class WaitUntil : IWaitUntil
106- {
107- /// <inheritdoc />
108- public async Task < bool > UntilAsync ( IContainer container )
109- {
110- // CosmosDB's preconfigured HTTP client will redirect the request to the container.
111- const string RequestUri = "http://localhost/alive" ;
112- using var httpClient = ( ( CosmosDbContainer ) container ) . HttpClientHealthCheck ;
113-
114- try
115- {
116- using var httpResponse = await httpClient
117- . GetAsync ( RequestUri )
118- . ConfigureAwait ( false ) ;
119-
120- /*
121- Example response from CosmosDB Emulator's /alive endpoint:
122-
123- HTTP/1.1 200 OK
124- Content-Type: application/json
125- Connection: close
126- Content-Length: 280
127-
128- {
129- "alive": true,
130- "checks": {
131- "explorer": "disabled",
132- "gateway": "healthy",
133- "postgres": "healthy"
134- },
135- "overall": true,
136- "protocol": "http",
137- "ready": true,
138- "status": "healthy",
139- "timestamp": "2026-02-28T08:52:40.328000942+00:00",
140- "version": "EN20260227"
141- }
142-
143- The following conditions will check that the endpoint returns a success status code
144- and that the "gateway" and "postgres" checks are healthy, which indicates that the CosmosDB Emulator is ready to accept requests.
145- This is because sometimes the /alive endpoint may return a successful response before the CosmosDB Emulator is fully ready
146- to accept requests. Checking the "gateway" and "postgres" checks can provide a more reliable indication of readiness.
147- */
148- if ( httpResponse . IsSuccessStatusCode )
149- {
150- var content = await httpResponse . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
151- using var jsonDocument = System . Text . Json . JsonDocument . Parse ( content ) ;
152- if ( jsonDocument . RootElement . TryGetProperty ( "checks" , out var checksProperty ) &&
153- checksProperty . TryGetProperty ( "gateway" , out var gatewayProperty ) &&
154- "healthy" . Equals ( gatewayProperty . GetString ( ) , StringComparison . OrdinalIgnoreCase ) &&
155- checksProperty . TryGetProperty ( "postgres" , out var postgresProperty ) &&
156- "healthy" . Equals ( postgresProperty . GetString ( ) , StringComparison . OrdinalIgnoreCase ) )
157- {
158- return true ;
159- }
160- }
161- }
162- catch { }
163-
164- return false ;
165- }
166- }
167- }
103+ }
0 commit comments