Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
unickq committed May 8, 2020
1 parent 6eb8f86 commit 7052ce5
Showing 1 changed file with 18 additions and 8 deletions.
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

0 comments on commit 7052ce5

Please sign in to comment.