Skip to content

Commit dbc4150

Browse files
committed
More output from E2E
1 parent c11966b commit dbc4150

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

.github/workflows/e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ jobs:
7878
if: always()
7979
with:
8080
name: playwright-traces
81-
path: .artifacts/playwright-traces/*-screenshot.jpeg
81+
path: .artifacts/playwright-traces/*
8282
retention-days: 1

tests/Elastic.OpenTelemetry.EndToEndTests/DistributedFixture/ApmUIBrowserContext.cs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ public class ApmUIBrowserContext : IAsyncLifetime
1414
{
1515
private readonly IConfigurationRoot _configuration;
1616
private readonly string _serviceName;
17+
private readonly string _playwrightScreenshotsDir;
18+
private readonly List<string> _output;
1719

18-
public ApmUIBrowserContext(IConfigurationRoot configuration, string serviceName)
20+
public ApmUIBrowserContext(IConfigurationRoot configuration, string serviceName, string playwrightScreenshotsDir, List<string> output)
1921
{
2022
_configuration = configuration;
2123
_serviceName = serviceName;
24+
_playwrightScreenshotsDir = playwrightScreenshotsDir;
25+
_output = output;
26+
2227
//"https://{instance}.apm.us-east-1.aws.elastic.cloud:443"
2328
// https://{instance}.kb.us-east-1.aws.elastic.cloud/app/apm/services?comparisonEnabled=true&environment=ENVIRONMENT_ALL&rangeFrom=now-15m&rangeTo=now&offset=1d
2429
var endpoint = configuration["E2E:Endpoint"]?.Trim() ?? string.Empty;
@@ -84,25 +89,35 @@ public async Task<IPage> OpenApmLandingPage(string testName)
8489
return page;
8590
}
8691

92+
private void Log(string message)
93+
{
94+
Console.WriteLine(message);
95+
_output.Add(message);
96+
}
97+
8798
public async Task WaitForServiceOnOverview(IPage page)
8899
{
89100
var timeout = (float)TimeSpan.FromSeconds(30).TotalMilliseconds;
90101

91102
var servicesHeader = page.GetByRole(AriaRole.Heading, new() { Name = "Services" });
92103
await servicesHeader.WaitForAsync(new() { State = WaitForSelectorState.Visible, Timeout = timeout });
93104

94-
Console.WriteLine($"Search for service name: {_serviceName}");
105+
await page.ScreenshotAsync(new() { Path = Path.Join(_playwrightScreenshotsDir, "services-loaded.jpeg"), FullPage = true });
106+
107+
Log($"Search for service name: {_serviceName}");
95108

96109
//service.name : dotnet-e2e-*
97110
var queryBar = page.GetByRole(AriaRole.Searchbox, new() { Name = "Search services by name" });
98111
await queryBar.WaitForAsync(new() { State = WaitForSelectorState.Visible, Timeout = timeout });
99112
await queryBar.FillAsync(_serviceName);
100113
await queryBar.PressAsync("Enter");
101114

115+
await page.ScreenshotAsync(new() { Path = Path.Join(_playwrightScreenshotsDir, "filter-services.jpeg"), FullPage = true });
116+
102117
Exception? observed = null;
103118

104119
var refreshTimeout = (float)TimeSpan.FromSeconds(5).TotalMilliseconds;
105-
for (var i = 0; i < 10; i++)
120+
for (var i = 0; i < 20; i++)
106121
{
107122
try
108123
{
@@ -113,10 +128,7 @@ public async Task WaitForServiceOnOverview(IPage page)
113128
}
114129
catch (Exception e)
115130
{
116-
await page.ScreenshotAsync(new() { Path = $"squibble{i}.jpeg", FullPage = true });
117-
118131
observed ??= e;
119-
await page.ReloadAsync();
120132
}
121133
finally
122134
{
@@ -125,31 +137,32 @@ public async Task WaitForServiceOnOverview(IPage page)
125137
}
126138
if (observed != null)
127139
throw observed; //TODO proper rethrow with stack
128-
129140
}
130141

131142
private int _unnamedTests;
132143
public async Task StopTrace(IPage page, bool success, [CallerMemberName] string? testName = null)
133144
{
134145
testName ??= $"unknown_test_{_unnamedTests++}";
135-
//only dump trace zip of test name is provided.
146+
147+
//only dump trace zip if tests failed
136148
if (success)
149+
{
137150
await page.Context.Tracing.StopAsync(new());
151+
}
138152
else
139153
{
140154
var root = DotNetRunApplication.GetSolutionRoot();
141155
var zip = Path.Combine(root.FullName, ".artifacts", "playwright-traces", $"{testName}.zip");
142156
await page.Context.Tracing.StopAsync(new() { Path = zip });
143157

144-
using var archive = ZipFile.OpenRead(zip);
145-
var entries = archive.Entries.Where(e => e.FullName.StartsWith("resources") && e.FullName.EndsWith(".jpeg")).ToList();
146-
var lastScreenshot = entries.MaxBy(e => e.LastWriteTime);
147-
lastScreenshot?.ExtractToFile(Path.Combine(root.FullName, ".artifacts", "playwright-traces", $"{testName}-screenshot.jpeg"));
158+
//using var archive = ZipFile.OpenRead(zip);
159+
//var entries = archive.Entries.Where(e => e.FullName.StartsWith("resources") && e.FullName.EndsWith(".jpeg")).ToList();
160+
//var lastScreenshot = entries.MaxBy(e => e.LastWriteTime);
161+
//lastScreenshot?.ExtractToFile(Path.Combine(root.FullName, ".artifacts", "playwright-traces", $"{testName}-screenshot.jpeg"));
148162
}
149163
await page.CloseAsync();
150164
}
151165

152-
153166
public async Task DisposeAsync()
154167
{
155168
await Browser.DisposeAsync();

tests/Elastic.OpenTelemetry.EndToEndTests/DistributedFixture/DistributedApplicationFixture.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
using System.Security.Cryptography;
77
using System.Text;
88
using Microsoft.Extensions.Configuration;
9+
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
910
using Nullean.Xunit.Partitions.Sdk;
11+
using Xunit.Abstractions;
1012

1113
namespace Elastic.OpenTelemetry.EndToEndTests.DistributedFixture;
1214

@@ -18,11 +20,14 @@ public class DistributedApplicationFixture : IPartitionLifetime
1820

1921
public bool Started => AspNetApplication.ProcessId.HasValue;
2022

23+
public string PlaywrightScreenshotsDirectory { get; } = Path.Combine(DotNetRunApplication.GetSolutionRoot().FullName, ".artifacts", "playwright-traces", "screenshots");
24+
2125
private readonly List<string> _output = [];
2226

2327
public int? MaxConcurrency => null;
2428

2529
private ApmUIBrowserContext? _apmUI;
30+
2631
public ApmUIBrowserContext ApmUI
2732
{
2833
get => _apmUI ??
@@ -42,11 +47,7 @@ public AspNetCoreExampleApplication AspNetApplication
4247
private static string ShaForCurrentTicks()
4348
{
4449
var buffer = Encoding.UTF8.GetBytes(DateTime.UtcNow.Ticks.ToString(DateTimeFormatInfo.InvariantInfo));
45-
46-
return BitConverter.ToString(SHA1.Create().ComputeHash(buffer))
47-
.Replace("-", "")
48-
.ToLowerInvariant()
49-
.Substring(0, 12);
50+
return Convert.ToHexStringLower(SHA1.HashData(buffer)).Substring(0, 12);
5051
}
5152

5253
public string FailureTestOutput()
@@ -66,6 +67,18 @@ public string FailureTestOutput()
6667

6768
}
6869

70+
public void WriteFailureTestOutput(ITestOutputHelper testOutputHelper)
71+
{
72+
foreach (var line in _output)
73+
testOutputHelper.WriteLine(line);
74+
75+
DotNetRunApplication.IterateOverLog(s =>
76+
{
77+
Console.WriteLine(s);
78+
testOutputHelper.WriteLine(s);
79+
});
80+
}
81+
6982
public async Task DisposeAsync()
7083
{
7184
_aspNetApplication?.Dispose();
@@ -91,7 +104,7 @@ public async Task InitializeAsync()
91104

92105
Log("Started ASP.NET application");
93106

94-
ApmUI = new ApmUIBrowserContext(configuration, ServiceName);
107+
ApmUI = new ApmUIBrowserContext(configuration, ServiceName, PlaywrightScreenshotsDirectory, _output);
95108

96109
Log("Started UI Browser context");
97110

tests/Elastic.OpenTelemetry.EndToEndTests/ServiceTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public async Task LatencyShowsAGraph()
3434
.ToBeVisibleAsync(new() { Timeout = timeout });
3535
}
3636

37-
3837
public async Task InitializeAsync() => _page = await fixture.ApmUI.NewProfiledPage(_testName);
3938

4039
public async Task DisposeAsync()
@@ -45,6 +44,6 @@ public async Task DisposeAsync()
4544
if (success)
4645
return;
4746

48-
DotNetRunApplication.IterateOverLog(Output.WriteLine);
47+
fixture.WriteFailureTestOutput(Output);
4948
}
5049
}

0 commit comments

Comments
 (0)