Skip to content

Commit d1d9548

Browse files
committed
Try self-contained
1 parent 490c769 commit d1d9548

File tree

6 files changed

+39
-18
lines changed

6 files changed

+39
-18
lines changed

src/Components/benchmarkapps/Wasm.Performance/Driver/BenchmarkResultsStartup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text.Json;
66
using Microsoft.AspNetCore.Builder;
77
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.Http;
89
using Microsoft.Extensions.DependencyInjection;
910
using Microsoft.Extensions.Hosting;
1011

@@ -22,12 +23,13 @@ public void Configure(IApplicationBuilder app)
2223
{
2324
app.UseCors();
2425

25-
app.Run(async request =>
26+
app.Run(async context =>
2627
{
27-
var result = await JsonSerializer.DeserializeAsync<List<BenchmarkResult>>(request.Request.Body, new JsonSerializerOptions
28+
var result = await JsonSerializer.DeserializeAsync<List<BenchmarkResult>>(context.Request.Body, new JsonSerializerOptions
2829
{
2930
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
3031
});
32+
await context.Response.WriteAsync("OK");
3133
Program.SetBenchmarkResult(result);
3234
});
3335
}

src/Components/benchmarkapps/Wasm.Performance/Driver/Program.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Diagnostics;
76
using System.IO;
87
using System.Linq;
98
using System.Runtime.ExceptionServices;
@@ -40,8 +39,10 @@ public static async Task<int> Main(string[] args)
4039
// This write is required for the benchmarking infrastructure.
4140
Console.WriteLine("Application started.");
4241

43-
using var browser = await Selenium.CreateBrowser(seleniumPort);
42+
var cancellationToken = new CancellationTokenSource(Timeout);
43+
cancellationToken.Token.Register(() => benchmarkResult.TrySetException(new TimeoutException($"Timed out after {Timeout}")));
4444

45+
using var browser = await Selenium.CreateBrowser(seleniumPort, cancellationToken.Token);
4546
using var testApp = StartTestApp();
4647
using var benchmarkReceiver = StartBenchmarkResultReceiver();
4748

@@ -54,9 +55,6 @@ public static async Task<int> Main(string[] args)
5455
browser.Url = launchUrl;
5556
browser.Navigate();
5657

57-
var cancellationToken = new CancellationTokenSource(Timeout);
58-
cancellationToken.Token.Register(() => benchmarkResult.TrySetException(new TimeoutException($"Timed out after {Timeout}")));
59-
6058
var results = await benchmarkResult.Task;
6159
FormatAsBenchmarksOutput(results);
6260

src/Components/benchmarkapps/Wasm.Performance/Driver/Selenium.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Linq;
56
using System.Net;
67
using System.Net.Http;
8+
using System.Threading;
79
using System.Threading.Tasks;
810
using OpenQA.Selenium;
911
using OpenQA.Selenium.Chrome;
@@ -14,8 +16,9 @@ namespace Wasm.Performance.Driver
1416
class Selenium
1517
{
1618
static bool RunHeadlessBrowser = true;
19+
static bool PoolForBrowserLogs = true;
1720

18-
private static async ValueTask<Uri> WaitForServerAsync(int port)
21+
private static async ValueTask<Uri> WaitForServerAsync(int port, CancellationToken cancellationToken)
1922
{
2023
var uri = new UriBuilder("http", "localhost", port, "/wd/hub/").Uri;
2124
var httpClient = new HttpClient
@@ -34,7 +37,7 @@ private static async ValueTask<Uri> WaitForServerAsync(int port)
3437
retries++;
3538
try
3639
{
37-
var response = (await httpClient.GetAsync("status")).EnsureSuccessStatusCode();
40+
var response = (await httpClient.GetAsync("status", cancellationToken)).EnsureSuccessStatusCode();
3841
Console.WriteLine("Connected to Selenium");
3942
return uri;
4043
}
@@ -52,9 +55,9 @@ private static async ValueTask<Uri> WaitForServerAsync(int port)
5255
throw new Exception($"Unable to connect to selenium-server at {uri}");
5356
}
5457

55-
public static async Task<RemoteWebDriver> CreateBrowser(int port)
58+
public static async Task<RemoteWebDriver> CreateBrowser(int port, CancellationToken cancellationToken)
5659
{
57-
var uri = await WaitForServerAsync(port);
60+
var uri = await WaitForServerAsync(port, cancellationToken);
5861

5962
var options = new ChromeOptions();
6063

@@ -82,6 +85,25 @@ public static async Task<RemoteWebDriver> CreateBrowser(int port)
8285

8386
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1);
8487

88+
if (PoolForBrowserLogs)
89+
{
90+
// Run in background.
91+
var logs = new RemoteLogs(driver);
92+
_ = Task.Run(async () =>
93+
{
94+
while (!cancellationToken.IsCancellationRequested)
95+
{
96+
await Task.Delay(TimeSpan.FromSeconds(3));
97+
98+
var consoleLogs = logs.GetLog(LogType.Browser);
99+
foreach (var entry in consoleLogs)
100+
{
101+
Console.WriteLine($"[Browser Log]: {entry.Timestamp}: {entry.Message}");
102+
}
103+
}
104+
});
105+
}
106+
85107
return driver;
86108
}
87109
catch (Exception ex)

src/Components/benchmarkapps/Wasm.Performance/TestApp/wwwroot/benchmarks/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { groups, BenchmarkEvent, onBenchmarkEvent } from './lib/minibench/minibench.js';
22
import { HtmlUI } from './lib/minibench/minibench.ui.js';
3-
// import './appStartup.js';
4-
// import './renderList.js';
3+
import './appStartup.js';
4+
import './renderList.js';
55
import './jsonHandling.js';
66

77
new HtmlUI('E2E Performance', '#display');
@@ -21,6 +21,7 @@ if (location.href.indexOf('#automated') !== -1) {
2121
break;
2222
case BenchmarkEvent.benchmarkCompleted:
2323
case BenchmarkEvent.benchmarkError:
24+
console.log(`Completed benchmark ${args.name}`);
2425
benchmarksResults.push(args);
2526
break;
2627
case BenchmarkEvent.runCompleted:

src/Components/benchmarkapps/Wasm.Performance/TestApp/wwwroot/benchmarks/lib/minibench/minibench.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class Group extends EventEmitter {
302302
}
303303

304304
const groups = [];
305-
let reportBenchmarkEvent;
305+
let reportBenchmarkEvent = () => {};
306306

307307
function group(name, configure) {
308308
groups.push(new Group(name));

src/Components/test/E2ETest/Tests/PerformanceTest.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ public void BenchmarksRunWithoutError()
5252
() => runAllButton.Displayed || Browser.FindElements(By.CssSelector(".benchmark-error")).Any(),
5353
TimeSpan.FromSeconds(60));
5454

55-
var finishedBenchmarks = Browser.FindElements(By.CssSelector(".benchmark-idle"));
56-
var failedBenchmarks = Browser.FindElements(By.CssSelector(".benchmark-error"));
57-
Assert.NotEmpty(finishedBenchmarks);
58-
Assert.Empty(failedBenchmarks);
55+
Browser.DoesNotExist(By.CssSelector(".benchmark-error")); // no failures
56+
Browser.Exists(By.CssSelector(".benchmark-idle")); // everything's done
5957
}
6058
}
6159
}

0 commit comments

Comments
 (0)