Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix await issues #107

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions Allure.Commons/Storage/AllureStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ namespace Allure.Commons.Storage
{
internal class AllureStorage
{
private readonly ThreadLocal<LinkedList<string>> stepContext = new ThreadLocal<LinkedList<string>>(() =>
#if !(NET45)
private readonly AsyncLocal<LinkedList<string>> stepContextLocal = new AsyncLocal<LinkedList<string>>();

private LinkedList<string> stepContext
{
return new LinkedList<string>();
});
get => stepContextLocal.Value ?? (stepContextLocal.Value = new LinkedList<string>());
set => stepContextLocal.Value = value;
}
#else
// May throw errors when await is using
private readonly ThreadLocal<LinkedList<string>> stepContextLocal =
new ThreadLocal<LinkedList<string>>(() => new LinkedList<string>());

private LinkedList<string> stepContext => stepContextLocal.Value;
#endif
private readonly ConcurrentDictionary<string, object> storage = new ConcurrentDictionary<string, object>();

public T Get<T>(string uuid)
Expand All @@ -31,27 +41,27 @@ public T Remove<T>(string uuid)

public void ClearStepContext()
{
stepContext.Value.Clear();
stepContext.Clear();
}

public void StartStep(string uuid)
{
stepContext.Value.AddFirst(uuid);
stepContext.AddFirst(uuid);
}

public void StopStep()
{
stepContext.Value.RemoveFirst();
stepContext.RemoveFirst();
}

public string GetRootStep()
{
return stepContext.Value.Last?.Value;
return stepContext.Last?.Value;
}

public string GetCurrentStep()
{
return stepContext.Value.First?.Value;
return stepContext.First?.Value;
}

public void AddStep(string parentUuid, string uuid, StepResult stepResult)
Expand Down