Skip to content

Commit

Permalink
Use Concurrent Queue as access is multithreaded
Browse files Browse the repository at this point in the history
  • Loading branch information
agray committed Jan 21, 2025
1 parent 56b89ec commit 5ccd18c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
46 changes: 24 additions & 22 deletions Saucery.Core/Dojo/BrowserVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Saucery.Core.OnDemand.Base;
using Saucery.Core.RestAPI;
using Saucery.Core.Util;
using System.Text;
using System.Collections.Concurrent;

namespace Saucery.Core.Dojo;

Expand Down Expand Up @@ -37,7 +37,7 @@ public class BrowserVersion

public List<string> ScreenResolutions { get; set; }

private StringBuilder TestNameBuilder { get; set; }
private ConcurrentQueue<string> TestNameQueue { get; set; }

public BrowserVersion(SupportedPlatform sp, BrowserBase b)
{
Expand All @@ -53,7 +53,7 @@ public BrowserVersion(SupportedPlatform sp, BrowserBase b)
RecommendedAppiumVersion = sp.recommended_backend_version!;
SupportedBackendVersions = sp.supported_backend_versions!;
DeprecatedBackendVersions = sp.deprecated_backend_versions!;
TestNameBuilder = new StringBuilder();
TestNameQueue = new ConcurrentQueue<string>();
}

public BrowserVersion(BrowserBase b,
Expand All @@ -74,7 +74,7 @@ public BrowserVersion(BrowserBase b,
SupportedBackendVersions = supportedBackendVersions!;
DeprecatedBackendVersions = deprecatedBackendVersions!;
ScreenResolutions = b.ScreenResolutions;
TestNameBuilder = new StringBuilder();
TestNameQueue = new ConcurrentQueue<string>();
}

public BrowserVersion(SaucePlatform platform) {
Expand All @@ -92,51 +92,53 @@ public BrowserVersion(SaucePlatform platform) {
ScreenResolution = string.Empty;
PlatformType = platform.IsAnAndroidDevice() ? PlatformType.Android : PlatformType.Apple;
ScreenResolutions = [];
TestNameBuilder = new StringBuilder();
TestNameQueue = new ConcurrentQueue<string>();
}

public void SetTestName(string testName)
{
TestNameBuilder = new StringBuilder();
TestNameBuilder.Append(testName.Contains(SauceryConstants.LEFT_SQUARE_BRACKET)
? testName[..testName.IndexOf(SauceryConstants.LEFT_SQUARE_BRACKET, StringComparison.Ordinal)]
: testName);
TestNameQueue = new ConcurrentQueue<string>();
if(!TestNameQueue.Contains(testName))
{
TestNameQueue.Enqueue(testName.Contains(SauceryConstants.LEFT_SQUARE_BRACKET)
? testName[..testName.IndexOf(SauceryConstants.LEFT_SQUARE_BRACKET, StringComparison.Ordinal)]
: testName);
}

if (this.IsAMobileDevice())
{
AppendPlatformField(DeviceName);
EnqueuePlatformField(DeviceName);

if (!string.IsNullOrEmpty(DeviceOrientation))
{
AppendPlatformField(DeviceOrientation);
EnqueuePlatformField(DeviceOrientation);
}
}
else
{
AppendPlatformField(Os);
AppendPlatformField(BrowserName);
AppendPlatformField(Name!);
EnqueuePlatformField(Os);
EnqueuePlatformField(BrowserName);
EnqueuePlatformField(Name!);

if (!string.IsNullOrEmpty(ScreenResolution))
{
AppendPlatformField(ScreenResolution);
EnqueuePlatformField(ScreenResolution);
}
}

if(TestNameBuilder.Length > 0)
if(!TestNameQueue.IsEmpty)
{
TestName = TestNameBuilder?.ToString();
TestName = string.Join("", TestNameQueue);
}
}

private void AppendPlatformField(string fieldToAdd)
private void EnqueuePlatformField(string fieldToAdd)
{
if(!string.IsNullOrEmpty(fieldToAdd) &&
//TestNameBuilder != null &&
TestNameBuilder?.Length > 0 &&
!TestNameBuilder.ToString().Contains(fieldToAdd))
!TestNameQueue.IsEmpty &&
!TestNameQueue.Contains(fieldToAdd))
{
TestNameBuilder.Append($"{SauceryConstants.UNDERSCORE}{fieldToAdd}");
TestNameQueue.Enqueue($"{SauceryConstants.UNDERSCORE}{fieldToAdd}");
}
}
}
2 changes: 1 addition & 1 deletion Saucery.Core/Saucery.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<PackageId>Saucery.Core</PackageId>
<PackageVersion>4.5.12</PackageVersion>
<PackageVersion>4.5.13</PackageVersion>
<Authors>Andrew Gray</Authors>
<Company>SauceForge</Company>
<Copyright>Copyright Andrew Gray 2014</Copyright>
Expand Down
2 changes: 1 addition & 1 deletion Saucery.Playwright.NUnit/Saucery.Playwright.NUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<PackageId>Saucery</PackageId>
<PackageVersion>4.5.12</PackageVersion>
<PackageVersion>4.5.13</PackageVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Authors>Andrew Gray</Authors>
<Company>SauceForge</Company>
Expand Down
2 changes: 1 addition & 1 deletion Saucery.XUnit/Saucery.XUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<PackageId>Saucery.XUnit</PackageId>
<PackageVersion>4.5.12</PackageVersion>
<PackageVersion>4.5.13</PackageVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Authors>Andrew Gray</Authors>
<Company>SauceForge</Company>
Expand Down
2 changes: 1 addition & 1 deletion Saucery/Saucery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<PackageId>Saucery</PackageId>
<PackageVersion>4.5.12</PackageVersion>
<PackageVersion>4.5.13</PackageVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Authors>Andrew Gray</Authors>
<Company>SauceForge</Company>
Expand Down

0 comments on commit 5ccd18c

Please sign in to comment.