Skip to content

Commit 6bcdbd7

Browse files
committed
Apply a slightly more efficient approach to service waiting
1 parent 62b3d71 commit 6bcdbd7

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/Couchbase.Aspire.Hosting/Orchestration/CouchbaseClusterOrchestrator.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -463,33 +463,29 @@ public async Task InitializeClusterAsync(ICouchbaseApi api, CouchbaseServerResou
463463

464464
public async Task WaitForServicesAsync(ICouchbaseApi api, CouchbaseServerResource server, CancellationToken cancellationToken = default)
465465
{
466+
if (!server.TryGetEndpoints(out var endpoints))
467+
{
468+
throw new InvalidOperationException("Failed to get node endpoints.");
469+
}
470+
471+
var expectedServiceNames = endpoints
472+
.Select(endpoint => CouchbaseEndpointNames.EndpointNameServiceMappings.TryGetValue(endpoint.Name, out var serviceName)
473+
? serviceName
474+
: null!)
475+
.Where(serviceName => serviceName is not null)
476+
.ToHashSet();
477+
466478
while (true)
467479
{
468480
cancellationToken.ThrowIfCancellationRequested();
469481

470-
if (!server.TryGetEndpoints(out var endpoints))
471-
{
472-
throw new InvalidOperationException("Failed to get node endpoints.");
473-
}
474-
475482
var node = await api.GetNodeServicesAsync(server, cancellationToken).ConfigureAwait(false);
476483

477484
if (node.Services is not null)
478485
{
479-
var allServicesFound = true;
480-
foreach (var endpoint in endpoints)
481-
{
482-
if (CouchbaseEndpointNames.EndpointNameServiceMappings.TryGetValue(endpoint.Name, out var serviceName))
483-
{
484-
if (!node.Services.ContainsKey(serviceName))
485-
{
486-
allServicesFound = false;
487-
break;
488-
}
489-
}
490-
}
486+
var nodeServiceNames = node.Services.Keys.ToHashSet();
491487

492-
if (allServicesFound)
488+
if (nodeServiceNames.IsSupersetOf(expectedServiceNames))
493489
{
494490
return;
495491
}

0 commit comments

Comments
 (0)