Skip to content

Commit 6a7516b

Browse files
committed
Handle disposing enumerators for PoolUsageMetrics response
1 parent d9cc0d1 commit 6a7516b

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/ResourceManager/AzureBatch/Commands.Batch.Test/BatchTestHelpers.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -392,27 +392,34 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
392392
}
393393

394394
/// <summary>
395-
/// Builds a CloudPoolUsageMetricsResponse object.
395+
/// Builds a CloudPoolUsageMetricsResponse object. Note: The lengths of all three lists must be the same.
396396
/// </summary>
397397
public static AzureOperationResponse<IPage<ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListPoolUsageMetricsHeaders> CreatePoolListUsageMetricsResponse(
398398
IEnumerable<string> poolIds,
399399
IEnumerable<DateTime> startTimes,
400400
IEnumerable<DateTime> endTimes)
401401
{
402-
var s = startTimes.GetEnumerator();
403-
var e = endTimes.GetEnumerator();
404-
var p = poolIds.GetEnumerator();
405402
var poolUsageList = new List<ProxyModels.PoolUsageMetrics>();
406403

407-
// Create x PoolUsageMetrics where x is the smallest length of the three lists
408-
while (s.MoveNext() && e.MoveNext() && p.MoveNext())
404+
// Validate the lengths of the lists are equal
405+
if (!(poolIds.Count() == startTimes.Count() && startTimes.Count() == endTimes.Count()))
409406
{
410-
poolUsageList.Add(new ProxyModels.PoolUsageMetrics()
407+
throw new ArgumentException("The lists length are not equal.");
408+
}
409+
410+
using (var startTimeEnumerator = startTimes.GetEnumerator())
411+
using (var endTimeEnumerator = endTimes.GetEnumerator())
412+
using (var poolIdEnumerator = poolIds.GetEnumerator())
413+
{
414+
while (startTimeEnumerator.MoveNext() && endTimeEnumerator.MoveNext() && poolIdEnumerator.MoveNext())
411415
{
412-
PoolId = p.Current,
413-
StartTime = s.Current,
414-
EndTime = e.Current
415-
});
416+
poolUsageList.Add(new ProxyModels.PoolUsageMetrics()
417+
{
418+
PoolId = poolIdEnumerator.Current,
419+
StartTime = startTimeEnumerator.Current,
420+
EndTime = endTimeEnumerator.Current
421+
});
422+
}
416423
}
417424

418425
var response = new AzureOperationResponse

src/ResourceManager/AzureBatch/Commands.Batch/Microsoft.Azure.Commands.Batch.dll-Help.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4511,7 +4511,7 @@
45114511
<dev:remarks>
45124512
<maml:para>Description</maml:para>
45134513
<maml:para>-----------</maml:para>
4514-
<maml:para>These commands return all of the pool usage metrics, aggregated by each pool between Monday, May 16, 2016 12:00:00 AM and Monday, May 16, 2016 1:00:00 AM</maml:para>
4514+
<maml:para>This command returns all of the pool usage metrics, aggregated by pool across time intervals between Monday, May 16, 2016 12:00:00 AM and Monday, May 16, 2016 1:00:00 AM</maml:para>
45154515
</dev:remarks>
45164516
</command:example>
45174517
<command:example>
@@ -4536,7 +4536,7 @@
45364536
<dev:remarks>
45374537
<maml:para>Description</maml:para>
45384538
<maml:para>-----------</maml:para>
4539-
<maml:para>The command gets the usage metrics for pool MyPool with a filter string.</maml:para>
4539+
<maml:para>This command returns the usage metrics for pool MyPool with a filter string.</maml:para>
45404540
</dev:remarks>
45414541
</command:example>
45424542
</command:examples>

0 commit comments

Comments
 (0)