Skip to content

Add support for async NUnit tests#314

Merged
neparij merged 2 commits into
allure-framework:mainfrom
overlord:support-async-nunit
Dec 30, 2022
Merged

Add support for async NUnit tests#314
neparij merged 2 commits into
allure-framework:mainfrom
overlord:support-async-nunit

Conversation

@overlord

@overlord overlord commented Dec 26, 2022

Copy link
Copy Markdown
Contributor

This pull request provides workaround or maybe even fixes the issues (in Allure.NUnit 2.9.2-preview.1) with async test methods in NUnit.Allure.

It fixes the case when async methods marked with [AllureStep] like the following:

[AllureStep("...")]
public async Task EnsureDeletedStep(string itemCode)
{ ... }

fails in runtime with exception like the following:

System.ArgumentNullException : Value cannot be null. (Parameter 'key')
---
Stack Trace:
ThrowHelper.ThrowArgumentNullException(String name)
ConcurrentDictionary`2.TryGetValue(TKey key, TValue& value)
ConcurrentDictionary`2.get_Item(TKey key)
AllureStorage.Get[T](String uuid)
AllureStorage.AddStep(String parentUuid, String uuid, StepResult stepResult)
AllureLifecycle.StartStep(String parentUuid, String uuid, StepResult stepResult)
AllureLifecycle.StartStep(String uuid, StepResult result)
AllureStepAspect.WrapStep(String name, MethodBase methodBase, Object[] arguments, Func`2 method)
...

The main problem was in the ThreadStatic field AllureStorage.stepContext - that fails on cross-thread execution of async methods.

I have tried to fix it and have provided some unit tests for new async behaviour (see. Allure.NUnit.AsyncTests.AsyncLifeCycleTests)

@neparij

neparij commented Dec 29, 2022

Copy link
Copy Markdown
Contributor

Hello, @overlord !
Thank you for contributing to Allure!
I'll look your PR and provide the feedback soon.

Looks like it solves this issue completely.

@neparij neparij left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution, could you look at review?

Comment thread Allure.NUnit.AsyncTests/Allure.NUnit.AsyncTests.csproj Outdated
Comment thread Allure.NUnit.AsyncTests/AsyncLifeCycleTests.cs Outdated
Comment thread Allure.NUnit.AsyncTests/AsyncOneTimeSetup.cs Outdated
Comment thread Allure.NUnit/Core/AllureExtensions.cs Outdated
Comment thread allure-csharp.sln Outdated
Comment thread Allure.NUnit.AsyncTests/AsyncOneTimeSetup.cs Outdated
Comment thread Allure.NUnit/Core/AllureNUnitAttribute.cs Outdated
@overlord overlord force-pushed the support-async-nunit branch from a90882d to c0fd75e Compare December 29, 2022 18:40
@overlord overlord requested review from neparij and undron and removed request for neparij and undron December 29, 2022 18:58

@neparij neparij left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove accidentally added file please.

Comment thread .editorconfig Outdated
@@ -0,0 +1,24 @@
# EditorConfig is awesome: http://EditorConfig.org

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants