From 527e87fff2e88ab8d0f9d7c2c9eabde02eb4609a Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Thu, 20 Feb 2025 08:15:13 -0800 Subject: [PATCH] Fix bug in `IntervalList` As provided by @DenisMayorko --- projects/RabbitMQ.Client/Util/IntAllocator.cs | 4 ++-- projects/Test/Unit/TestIntAllocator.cs | 8 +++----- projects/Test/Unit/Unit.csproj | 1 + 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/projects/RabbitMQ.Client/Util/IntAllocator.cs b/projects/RabbitMQ.Client/Util/IntAllocator.cs index 147698834..3bbcc53e2 100644 --- a/projects/RabbitMQ.Client/Util/IntAllocator.cs +++ b/projects/RabbitMQ.Client/Util/IntAllocator.cs @@ -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); diff --git a/projects/Test/Unit/TestIntAllocator.cs b/projects/Test/Unit/TestIntAllocator.cs index 3dce15103..d0eb33228 100644 --- a/projects/Test/Unit/TestIntAllocator.cs +++ b/projects/Test/Unit/TestIntAllocator.cs @@ -29,7 +29,6 @@ // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. //--------------------------------------------------------------------------- -using System; using System.Collections.Generic; using RabbitMQ.Client.Util; using Xunit; @@ -42,13 +41,12 @@ public class TestIntAllocator public void TestRandomAllocation() { int repeatCount = 10000; - int range = 100; + int range = 2048; IList allocated = new List(); 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) @@ -69,7 +67,7 @@ public void TestRandomAllocation() [Fact] public void TestAllocateAll() { - int range = 100; + int range = 2048; IList allocated = new List(); IntAllocator intAllocator = new IntAllocator(0, range); for (int i = 0; i <= range; i++) diff --git a/projects/Test/Unit/Unit.csproj b/projects/Test/Unit/Unit.csproj index 97acaf54c..3a18c796d 100644 --- a/projects/Test/Unit/Unit.csproj +++ b/projects/Test/Unit/Unit.csproj @@ -21,6 +21,7 @@ +