Skip to content

Commit

Permalink
Revert "[#255] changed ThreadLocal to AsyncLocal to be able to use as…
Browse files Browse the repository at this point in the history
…ync/awai…" (#120)

This reverts commit a28e501.
  • Loading branch information
mialeska authored Jul 18, 2024
1 parent a28e501 commit 98dd152
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ namespace Aquality.Selenium.Core.Applications
public abstract class AqualityServices<TApplication>
where TApplication : class, IApplication
{
private static readonly AsyncLocal<TApplication> AppContainer = new AsyncLocal<TApplication>();
private static readonly AsyncLocal<IServiceProvider> ServiceProviderContainer = new AsyncLocal<IServiceProvider>();
private static readonly ThreadLocal<TApplication> AppContainer = new ThreadLocal<TApplication>();
private static readonly ThreadLocal<IServiceProvider> ServiceProviderContainer = new ThreadLocal<IServiceProvider>();

protected AqualityServices()
{
}

protected static bool IsApplicationStarted()
{
return AppContainer.Value != null && AppContainer.Value.IsStarted;
return AppContainer.IsValueCreated && AppContainer.Value.IsStarted;
}

protected static TApplication GetApplication(Func<IServiceProvider, TApplication> startApplicationFunction, Func<IServiceCollection> serviceCollectionProvider = null)
Expand All @@ -36,7 +36,7 @@ protected static void SetApplication(TApplication application)

protected static IServiceProvider GetServiceProvider(Func<IServiceProvider, TApplication> applicationSupplier, Func<IServiceCollection> serviceCollectionProvider = null)
{
if (ServiceProviderContainer.Value == null)
if (!ServiceProviderContainer.IsValueCreated)
{
IServiceCollection services;
if (serviceCollectionProvider == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using OpenQA.Selenium;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Aquality.Selenium.Core.Tests.Applications.Browser.Elements;

namespace Aquality.Selenium.Core.Tests.Applications.Browser
Expand Down Expand Up @@ -104,15 +103,5 @@ public void Should_BePossibleTo_WorkWithElements_FoundByDottedLocator()
() => foundElements.Select(element => element.GetElement()).ToList(),
$"Failed to find elements using dotted locator [{DottedLoc}]");
}

[Test]
public async Task Should_BePossibleTo_To_Have_Async_Tests()
{
await Task.Delay(2000);
var foundElements = FindElements<Label>(DottedLoc, expectedCount: ElementsCount.MoreThenZero);
Assert.DoesNotThrow(
() => foundElements.Select(element => element.GetElement()).ToList(),
$"Failed to find elements using dotted locator [{DottedLoc}]");
}
}
}

0 comments on commit 98dd152

Please sign in to comment.