Skip to content

Commit eb64b79

Browse files
authored
Merge pull request #1785 from rabbitmq/rabbitmq-dotnet-client-1751-3
Fix bug in `IntervalList`
2 parents a8dcbc9 + 527e87f commit eb64b79

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

projects/RabbitMQ.Client/Util/IntAllocator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ public IntervalList(int start, int end)
184184
return x;
185185
}
186186

187-
if (x.End > y.Start)
187+
if (x.Start > y.Start)
188188
{
189-
return Merge(y, x);
189+
(x, y) = (y, x);
190190
}
191191

192192
Debug.Assert(x.End != y.Start);

projects/Test/Unit/TestIntAllocator.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
// Copyright (c) 2007-2025 Broadcom. All Rights Reserved.
3030
//---------------------------------------------------------------------------
3131

32-
using System;
3332
using System.Collections.Generic;
3433
using RabbitMQ.Client.Util;
3534
using Xunit;
@@ -42,13 +41,12 @@ public class TestIntAllocator
4241
public void TestRandomAllocation()
4342
{
4443
int repeatCount = 10000;
45-
int range = 100;
44+
int range = 2048;
4645
IList<int> allocated = new List<int>();
4746
IntAllocator intAllocator = new IntAllocator(0, range);
48-
Random rand = new Random();
4947
while (repeatCount-- > 0)
5048
{
51-
if (rand.Next(2) == 0)
49+
if (Util.S_Random.Next(2) == 0)
5250
{
5351
int a = intAllocator.Allocate();
5452
if (a > -1)
@@ -69,7 +67,7 @@ public void TestRandomAllocation()
6967
[Fact]
7068
public void TestAllocateAll()
7169
{
72-
int range = 100;
70+
int range = 2048;
7371
IList<int> allocated = new List<int>();
7472
IntAllocator intAllocator = new IntAllocator(0, range);
7573
for (int i = 0; i <= range; i++)

projects/Test/Unit/Unit.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
<ItemGroup>
2323
<ProjectReference Include="../../RabbitMQ.Client/RabbitMQ.Client.csproj" />
24+
<ProjectReference Include="../Common/Common.csproj" />
2425
</ItemGroup>
2526

2627
<ItemGroup>

0 commit comments

Comments
 (0)