Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Aug 30, 2023
1 parent 9cc796f commit de3d0d8
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions test/Grpc.Net.Client.Tests/Balancer/RoundRobinBalancerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ public async Task HasSubchannels_ResolverRefresh_MatchingSubchannelUnchanged()
var preservedSubchannel1 = subchannels[1];
var preservedSubchannel2 = subchannels[2];

await BalancerWaitHelpers.WaitForSubchannelsToBeReadyAsync(
serviceProvider.GetRequiredService<ILoggerFactory>().CreateLogger(GetType()),
channel.ConnectionManager,
expectedCount: 3).DefaultTimeout();

var address2 = new BalancerAddress("localhost", 82);
address2.Attributes.Set(new BalancerAttributesKey<int>("test"), 1);

Expand Down Expand Up @@ -395,24 +400,17 @@ await BalancerWaitHelpers.WaitForSubchannelsToBeReadyAsync(
// Test that the channel's address was updated with new attribute with new attributes.
Assert.AreSame(preservedSubchannel2.CurrentAddress, address2);

try
lock (subChannelConnections)
{
await TestHelpers.AssertIsTrueRetryAsync(() =>
try
{
lock (subChannelConnections)
{
return subChannelConnections.Count == 4;
}
}, "Wait for connections to be recorded.");

Assert.Contains(discardedSubchannel, subChannelConnections);
Assert.Contains(preservedSubchannel1, subChannelConnections);
Assert.Contains(preservedSubchannel2, subChannelConnections);
Assert.Contains(newSubchannel, subChannelConnections);
}
catch (Exception ex)
{
lock (subChannelConnections)
Assert.AreEqual(4, subChannelConnections.Count);
Assert.Contains(discardedSubchannel, subChannelConnections);
Assert.Contains(preservedSubchannel1, subChannelConnections);
Assert.Contains(preservedSubchannel2, subChannelConnections);
Assert.Contains(newSubchannel, subChannelConnections);
}
catch (Exception ex)
{
throw new Exception("Connected subchannels: " + Environment.NewLine + string.Join(Environment.NewLine, subChannelConnections), ex);
}
Expand Down

0 comments on commit de3d0d8

Please sign in to comment.