Skip to content

Commit

Permalink
[Service Bus] Handle cases where desired worker count exceeds int.Max…
Browse files Browse the repository at this point in the history
…Int (Azure#39474)

* handle long desired worker count

* adding additional unit test

* handle overflow

* Revert "adding additional unit test"

This reverts commit a0869c4.

* Revert "handle overflow"

This reverts commit dba0661.

* Revert "Revert "handle overflow""

This reverts commit bd6bd1d.

* Revert "handle long desired worker count"

This reverts commit e5a8756.

* add checked block

---------

Co-authored-by: Vincent Chiang <vchiang@microsoft.com>
  • Loading branch information
2 people authored and matthohn-msft committed Oct 27, 2023
1 parent 6eecd53 commit 29fb1fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,20 @@ internal TargetScalerResult GetScaleResultInternal(TargetScalerContext context,
throw new ArgumentOutOfRangeException($"Unexpected concurrency='{concurrency}' - the value must be > 0.");
}

int targetWorkerCount = (int)Math.Ceiling(messageCount / (decimal)concurrency);
int targetWorkerCount;

try
{
checked
{
targetWorkerCount = (int)Math.Ceiling(messageCount / (decimal)concurrency);
}
}
catch (OverflowException)
{
targetWorkerCount = int.MaxValue;
}

_logger.LogInformation($"Target worker count for function '{_functionId}' is '{targetWorkerCount}' (EntityPath='{_entityPath}', MessageCount ='{messageCount}', Concurrency='{concurrency}').");

return new TargetScalerResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public void Setup()
[TestCase(100, true, true, null, 4)]
[TestCase(100, false, true, 19, 6)]
[TestCase(100, false, false, null, 3)]
public void ServiceBusTargetScaler_Returns_Expected(int messageCount, bool isSessionEnabled, bool singleDispatch, int? concurrency,int expected)
[TestCase(100, false, false, null, 3)]
[TestCase(2147483650, false, false, 1, 2147483647)] // cap targetWorkerCount at int.MaxValue
[TestCase(2147483650, false, false, 2, 1073741825)]
public void ServiceBusTargetScaler_Returns_Expected(long messageCount, bool isSessionEnabled, bool singleDispatch, int? concurrency, int expected)
{
ServiceBusOptions options = new ServiceBusOptions
{
Expand Down

0 comments on commit 29fb1fe

Please sign in to comment.