question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create alternate GuardClauseAssertion that supports methods marked with `async`.

See original GitHub issue

As discussed in #268, the GuardClauseAssertion class does not wait the tasks to complete, making it unable to validate non fail fast methods.

This is completely understandable, since the fail fast is indeed the best option. Nevertheless, it seems impossible to implement fail fast behavior when dealing with methods marked with the async keyword.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
Kralizekcommented, Feb 11, 2021

@zvirja @aivascu could we reconsider this? I really don’t see why in 2021 async methods can’t be tested properly.

2reactions
zvirjacommented, May 30, 2019

@ploeh Basically, any async method is not fail-fast. Consider the following example:

public async Task<T> GuardedOpenGenericMethodReturningTaskResult<T>(object arg)
{
    if (arg == null) throw new ArgumentNullException(nameof(arg));

    await Task.Yield();

    return default;
}

This method doesn’t throw if you call it will null. Instead, the failed Task is returned. Therefore, the GuardClauseAssertion it its current form fails and complains about missing guard clause.

In real application almost all the code is async, therefore each invocation is awaited and exception is thrown immediately. So it’s completely OK that “fast-fail” principle is violated in a form that you should await Task to see exception.

Of course, you can re-write code somehow to make it fail immediately (create private function with async keyword and move all the logic there), but there is no practical sense to do it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrapping existing asynchronous code in async/await in Swift
In this post, I'll explore one of the options we have to convert existing, callback based, asynchronous code into functions that are marked...
Read more >
Async/Await, Combine, Closures: A Guide to Modern ...
A comparison between async/await, Combine, and closures in Swift. Includes an overview of the strengths and weaknesses of the different ...
Read more >
How Async/Await Really Works in C# - .NET Blog
So, we have Task , Task<TResult> , ValueTask , and ValueTask<TResult> . We're able to interact with them in various ways, representing ...
Read more >
[Concurrency] Interoperability with Objective-C - Pitches
Hello all, Swift's concurrency feature involves asynchronous functions and actors. While Objective-C does not have corresponding language ...
Read more >
Unit testing async/await Swift code
Unit testing async/await logic can be done by marking your unit test as asynchronous and using a new XCTest method.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found