Skip to content

Commit a87a5ee

Browse files
committed
4 ci
1 parent 5b6279a commit a87a5ee

2 files changed

Lines changed: 59 additions & 16 deletions

File tree

tests/PrompterOne.Testing/EnvironmentAwareParallelLimitBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace PrompterOne.Testing;
77
/// </summary>
88
public abstract class EnvironmentAwareParallelLimitBase : IParallelLimit
99
{
10-
protected virtual int CiLimit { get; } = 8;
10+
protected virtual int CiLimit { get; } = 4;
1111
protected virtual int LocalLimit { get; } = 15;
1212

1313
public int Limit => ResolveLimit();

tests/PrompterOne.Web.UITests/Infrastructure/StandaloneAppFixture.cs

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Net;
33
using System.Runtime.CompilerServices;
44
using Microsoft.Playwright;
5+
using PrompterOne.Testing;
56

67
namespace PrompterOne.Web.UITests;
78

@@ -79,11 +80,8 @@ private async Task<IPage> CreateAdditionalPageAsync()
7980

8081
try
8182
{
82-
var page = await context.NewPageAsync();
83-
PreparePage(page);
84-
await PrimeIsolatedBrowserStorageAsync(page);
85-
await WarmUpContextPageIfNeededAsync(page, BaseAddress);
86-
return page;
83+
await WarmUpContextWithSacrificialPageAsync(context);
84+
return await CreatePrimedPageAsync(context);
8785
}
8886
catch (PlaywrightException exception) when (attempt < ContextBootstrapAttemptCount && IsBrowserClosedException(exception))
8987
{
@@ -104,20 +102,13 @@ private async Task<IPage> CreateSharedPageAsync(string contextKey)
104102

105103
try
106104
{
107-
var page = await context.NewPageAsync();
108-
PreparePage(page);
109-
110105
if (isNewSharedContext)
111106
{
112-
await PrimeIsolatedBrowserStorageAsync(page);
113-
await WarmUpContextPageIfNeededAsync(page, BaseAddress, warmAllRuntimeRoutes: true);
114-
}
115-
else
116-
{
117-
await page.GotoAsync($"{BaseAddress}{UiTestHostConstants.BlankPagePath}");
107+
await WarmUpContextWithSacrificialPageAsync(context, warmAllRuntimeRoutes: true);
108+
return await CreatePrimedPageAsync(context);
118109
}
119110

120-
return page;
111+
return await CreateBlankPageAsync(context);
121112
}
122113
catch (PlaywrightException exception) when (attempt < ContextBootstrapAttemptCount && IsBrowserClosedException(exception))
123114
{
@@ -241,9 +232,61 @@ private static bool IsBrowserClosedException(PlaywrightException exception) =>
241232
private static bool IsContextWarmupFailure(InvalidOperationException exception) =>
242233
exception.Message.StartsWith("Browser context warmup failed.", StringComparison.Ordinal);
243234

235+
private async Task<IPage> CreatePrimedPageAsync(IBrowserContext context)
236+
{
237+
var page = await context.NewPageAsync();
238+
PreparePage(page);
239+
await PrimeIsolatedBrowserStorageAsync(page);
240+
return page;
241+
}
242+
243+
private async Task<IPage> CreateBlankPageAsync(IBrowserContext context)
244+
{
245+
var page = await context.NewPageAsync();
246+
PreparePage(page);
247+
await page.GotoAsync($"{BaseAddress}{UiTestHostConstants.BlankPagePath}");
248+
return page;
249+
}
250+
251+
private async Task WarmUpContextWithSacrificialPageAsync(IBrowserContext context, bool warmAllRuntimeRoutes = false)
252+
{
253+
if (!TestEnvironment.IsCiEnvironment)
254+
{
255+
return;
256+
}
257+
258+
var warmupPage = await context.NewPageAsync();
259+
260+
try
261+
{
262+
// Warm a disposable page so the returned test page stays clean and isolated.
263+
PreparePage(warmupPage);
264+
await PrimeIsolatedBrowserStorageAsync(warmupPage);
265+
await WarmUpContextPageIfNeededAsync(warmupPage, BaseAddress, warmAllRuntimeRoutes);
266+
}
267+
finally
268+
{
269+
await ClosePageAsync(warmupPage);
270+
}
271+
}
272+
244273
private Task PrimeIsolatedBrowserStorageAsync(IPage page) =>
245274
PrimeIsolatedBrowserStorageAsync(page, BaseAddress);
246275

276+
private static async Task ClosePageAsync(IPage page)
277+
{
278+
try
279+
{
280+
if (!page.IsClosed)
281+
{
282+
await page.CloseAsync();
283+
}
284+
}
285+
catch
286+
{
287+
}
288+
}
289+
247290
private static void PreparePage(IPage page)
248291
{
249292
page.SetDefaultNavigationTimeout(BrowserTestConstants.Timing.DefaultNavigationTimeoutMs);

0 commit comments

Comments
 (0)