Skip to content

Commit

Permalink
Fix for #2892: Timeout async guard inappropriately triggers with F# (v3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Feb 22, 2024
1 parent d9a5fa5 commit a073ae4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/xunit.v3.common/Utility/AsyncUtility.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand All @@ -13,6 +14,7 @@ namespace Xunit.Sdk;
public static class AsyncUtility
{
static MethodInfo? fSharpStartAsTaskOpenGenericMethod;
static readonly HashSet<string?> taskGenericTypes = new() { "Microsoft.FSharp.Control.FSharpAsync`1", "System.Threading.Tasks.Task`1", "System.Threading.Tasks.ValueTask`1" };

/// <summary>
/// Determines if the given method is async, as matters to xUnit.net. This means it either (a) returns
Expand All @@ -25,15 +27,17 @@ public static class AsyncUtility
/// <returns>Returns <c>true</c> if the method is async; returns <c>false</c> otherwise.</returns>
public static bool IsAsync(MethodInfo method)
{
Guard.ArgumentNotNull(method);

if (IsAsyncVoid(method))
return true;

var methodReturnType = method.ReturnType;
return methodReturnType == typeof(Task)
|| methodReturnType == typeof(ValueTask)
|| (methodReturnType.IsGenericType && methodReturnType.GetGenericTypeDefinition().FullName == "Microsoft.FSharp.Control.FSharpAsync`1");
if (methodReturnType == typeof(Task) || methodReturnType == typeof(ValueTask))
return true;

if (methodReturnType.GetTypeInfo().IsGenericType)
return taskGenericTypes.Contains(methodReturnType.GetGenericTypeDefinition().FullName);

return false;
}

/// <summary>
Expand Down

0 comments on commit a073ae4

Please sign in to comment.