Skip to content

test: Upgrade to XUnit 2.9.0, fix some test failures #2686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ updates:
- dependency-name: "Microsoft.VisualStudio.Threading.Analyzers"
- dependency-name: "NUnit*"
- dependency-name: "Selenium*"
# Enable xunit after we fix the v2.9.0 upgrade blocker https://github.com/newrelic/newrelic-dotnet-agent/issues/2684
# - dependency-name: "xunit*"
- dependency-name: "xunit*"
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.console" Version="2.8.0">
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.console" Version="2.9.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,37 @@ public AgentLogBase(ITestOutputHelper testLogger)

public abstract IEnumerable<string> GetFileLines();

public string GetAccountId(TimeSpan? timeoutOrZero = null)
public string GetAccountId()
{
var reportingAppLink = GetReportingAppLink(timeoutOrZero);
var reportingAppLink = GetReportingAppLink();
var reportingAppUri = new Uri(reportingAppLink);
var accountId = reportingAppUri.Segments[2];
if (accountId == null)
throw new Exception("Could not find account ID in second segment of reporting app link: " + reportingAppLink);
return accountId.TrimEnd('/');
}

public string GetApplicationId(TimeSpan? timeoutOrZero = null)
public string GetApplicationId()
{
var reportingAppLink = GetReportingAppLink(timeoutOrZero);
var reportingAppLink = GetReportingAppLink();
var reportingAppUri = new Uri(reportingAppLink);
var applicationId = reportingAppUri.Segments[4];
if (applicationId == null)
throw new Exception("Could not find application ID in second segment of reporting app link: " + reportingAppLink);
return applicationId.TrimEnd('/');
}

public string GetCrossProcessId(TimeSpan? timeoutOrZero = null)
public string GetCrossProcessId()
{
return $@"{GetAccountId()}#{GetApplicationId()}";
}

public string GetReportingAppLink(TimeSpan? timeoutOrZero = null)
private string GetReportingAppLink()
{
var match = WaitForLogLine(AgentReportingToLogLineRegex, timeoutOrZero);
var match = TryGetLogLine(AgentReportingToLogLineRegex);
if (!match.Success || match.Groups.Count < 2)
throw new Exception("Could not find reporting app link in log file.");

return match.Groups[1].Value;
}

Expand Down Expand Up @@ -164,23 +167,19 @@ public IEnumerable<Match> WaitForLogLines(string regularExpression, TimeSpan? ti

var timeout = timeoutOrZero ?? TimeSpan.Zero;

_testLogger?.WriteLine($"{Timestamp} WaitForLogLines Waiting for expression: {regularExpression}. Duration: {timeout.TotalSeconds:N0} seconds. Minimum count: {minimumCount}");

var timeTaken = Stopwatch.StartNew();
do
{
var matches = TryGetLogLines(regularExpression).ToList();
if (matches.Count >= minimumCount)
{
_testLogger?.WriteLine($"{Timestamp} WaitForLogLines Matched expression: {regularExpression} in {timeTaken.Elapsed.TotalSeconds:N1}s.");
return matches;
}

Thread.Sleep(TimeSpan.FromMilliseconds(100));
} while (timeTaken.Elapsed < timeout);

var message = $"{Timestamp} Log line did not appear a minimum of {minimumCount} times within {timeout.TotalSeconds:N0} seconds. Expected line expression: {regularExpression}";
_testLogger?.WriteLine(message);
throw new Exception(message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="xunit" version="2.8.0" />
<PackageReference Include="xunit.assert" Version="2.8.0" />
<PackageReference Include="xunit.core" Version="2.8.0" />
<PackageReference Include="xunit" version="2.9.0" />
<PackageReference Include="xunit.assert" Version="2.9.0" />
<PackageReference Include="xunit.core" Version="2.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Shared\TestSerializationHelpers\TestSerializationHelpers.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Selenium.Support" Version="4.17.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.17.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.assert" Version="2.8.0" />
<PackageReference Include="xunit.core" Version="2.8.0" />
<PackageReference Include="xunit.runner.console" Version="2.8.0">
<PackageReference Include="xunit.assert" Version="2.9.0" />
<PackageReference Include="xunit.core" Version="2.9.0" />
<PackageReference Include="xunit.runner.console" Version="2.9.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="CouchbaseNetClient" Version="2.3.8" />
<PackageReference Include="Oracle.ManagedDataAccess" Version="12.1.2400" />
<PackageReference Include="xunit" version="2.8.0" />
<PackageReference Include="xunit.assert" Version="2.8.0" />
<PackageReference Include="xunit.core" Version="2.8.0" />
<PackageReference Include="xunit" version="2.9.0" />
<PackageReference Include="xunit.assert" Version="2.9.0" />
<PackageReference Include="xunit.core" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.assert" Version="2.8.0" />
<PackageReference Include="xunit.core" Version="2.8.0" />
<PackageReference Include="xunit.runner.console" Version="2.8.0">
<PackageReference Include="xunit.assert" Version="2.9.0" />
<PackageReference Include="xunit.core" Version="2.9.0" />
<PackageReference Include="xunit.runner.console" Version="2.9.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading