Skip to content

Commit

Permalink
Add retries to ModulesAreDisposedWhenProcessIsDisposed (dotnet#68104)
Browse files Browse the repository at this point in the history
* Add retries to ModulesAreDisposedWhenProcessIsDisposed

* Update src/libraries/System.Diagnostics.Process/tests/ProcessModuleTests.cs

Co-authored-by: Adam Sitnik <[email protected]>

Co-authored-by: Adam Sitnik <[email protected]>
  • Loading branch information
2 people authored and Jo Shields committed Apr 21, 2022
1 parent d3fc061 commit 6089bd4
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
using System.Linq;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;
Expand Down Expand Up @@ -76,7 +77,15 @@ public void ModulesAreDisposedWhenProcessIsDisposed()
{
Process process = CreateDefaultProcess();

ProcessModuleCollection modulesCollection = process.Modules;
// Very rarely, this call will fail with ERROR_PARTIAL_COPY; it only happened
// so far on this particular test, the only one that creates a new process.
// Assumption is that we need to give a little extra time.
ProcessModuleCollection modulesCollection = null;
RetryHelper.Execute(() =>
{
modulesCollection = process.Modules;
}, maxAttempts: 5, backoffFunc: null, retryWhen: e => e.GetType() == typeof(Win32Exception));

int expectedCount = 0;
int disposedCount = 0;
foreach (ProcessModule processModule in modulesCollection)
Expand Down

0 comments on commit 6089bd4

Please sign in to comment.