Skip to content

Commit

Permalink
test: Upgrade to XUnit 2.9.0, fix some test failures (#2684) (#2686)
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr authored Aug 9, 2024
1 parent 18a17af commit d3117a4
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 29 deletions.
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
21 changes: 10 additions & 11 deletions tests/Agent/IntegrationTests/IntegrationTestHelpers/AgentLogBase.cs
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

0 comments on commit d3117a4

Please sign in to comment.