Skip to content

Fix bug in IntervalList #1785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions projects/RabbitMQ.Client/Util/IntAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ public IntervalList(int start, int end)
return x;
}

if (x.End > y.Start)
if (x.Start > y.Start)
{
return Merge(y, x);
(x, y) = (y, x);
}

Debug.Assert(x.End != y.Start);
Expand Down
8 changes: 3 additions & 5 deletions projects/Test/Unit/TestIntAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
// Copyright (c) 2007-2025 Broadcom. All Rights Reserved.
//---------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using RabbitMQ.Client.Util;
using Xunit;
Expand All @@ -42,13 +41,12 @@ public class TestIntAllocator
public void TestRandomAllocation()
{
int repeatCount = 10000;
int range = 100;
int range = 2048;
IList<int> allocated = new List<int>();
IntAllocator intAllocator = new IntAllocator(0, range);
Random rand = new Random();
while (repeatCount-- > 0)
{
if (rand.Next(2) == 0)
if (Util.S_Random.Next(2) == 0)
{
int a = intAllocator.Allocate();
if (a > -1)
Expand All @@ -69,7 +67,7 @@ public void TestRandomAllocation()
[Fact]
public void TestAllocateAll()
{
int range = 100;
int range = 2048;
IList<int> allocated = new List<int>();
IntAllocator intAllocator = new IntAllocator(0, range);
for (int i = 0; i <= range; i++)
Expand Down
1 change: 1 addition & 0 deletions projects/Test/Unit/Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<ItemGroup>
<ProjectReference Include="../../RabbitMQ.Client/RabbitMQ.Client.csproj" />
<ProjectReference Include="../Common/Common.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading