Skip to content

Commit

Permalink
Run test assemblies in parallel (#1106)
Browse files Browse the repository at this point in the history
This commit separates out the common test components
from Elastic.Apm.Tests into a new assembly,
Elastic.Apm.Tests.Utilities. This allows assemblies containing tests
to be run in parallel, which is not possible when test assemblies
reference another test assembly that may potentially be running
at the same time.

Update linux CI scripts to run tests by targeting the
solution file. In conjunction with the xunit.runner.json configuration,
this allows test assemblies to run in parallel.

Add coverlet and JunitXml.TestLogger packages to
all test projects using Directory.Build.Props in tests directory. 
This removes the need to add them in CI scripts or to each project individually.
Update packages to newer versions.

- Run tests with Release configuration
- Include only Elastic.Apm.* and exclude all Elastic.Apm test assemblies from code coverage
- Rename Elastic.Apm.DockerTests to Elastic.Apm.Docker.Tests for consistency
- Rename Elastic.Apm.PerfTests to Elastic.Apm.Benchmarks

- Use TestAgentComponents in test

  Update tests to use TestAgentComponents where possible, to
  mitigate intermittent failures with using AgentComponents 
  related to reading environment variables that may be set by other concurrently
  running tests

- Check token cancellation in Workloop

  check token cancellation in the BackendCommComponentBase Workloop, 
  and break if cancellation is requested.

- Don't Use SourceLink in coverlet.settings

  Jenkins cannot display Sourcelinked source code

- Fix hanging tests

  Remove netcoreapp2.2 from tests. netcoreapp2.2 consistently hangs in
  CI on Linux due to MSBuild worker node reuse by dotnet test. This is
  the issue outlined in dotnet/sdk#9452 (comment).

  Setting `nodereuse:false` when running linux dotnet test on netcoreapp2.2 fixes the
  tests hanging, but since netcoreapp2.2 is EOL by Microsoft on December 23, 2019
  (https://dotnet.microsoft.com/platform/support/policy/dotnet-core), netcoreapp2.2
  has been removed from tests in line with the policy that we should only support
  versions that are supported by Microsoft.
  • Loading branch information
russcam authored Jan 14, 2021
1 parent 7e30d2d commit 5fa5a36
Show file tree
Hide file tree
Showing 177 changed files with 552 additions and 541 deletions.
2 changes: 1 addition & 1 deletion .ci/linux/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#
set -euxo pipefail

cd ./test/Elastic.Apm.PerfTests
cd ./test/Elastic.Apm.Benchmarks
dotnet run -c Release --filter AspNetCoreLoadTestWithAgent AspNetCoreLoadTestWithoutAgent
dotnet run -c Release --filter *CollectAllMetrics2X* *Simple100Transaction10Spans* *SimpleTransactionsWith*
2 changes: 1 addition & 1 deletion .ci/linux/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if [ "${VERSION_SUFFIX_ENABLED}" = "true" ]; then
fi

# Remove sample projects - and other we don't want to pack
dotnet sln remove test/Elastic.Apm.PerfTests/Elastic.Apm.PerfTests.csproj
dotnet sln remove test/Elastic.Apm.Benchmarks/Elastic.Apm.Benchmarks.csproj
dotnet sln remove test/Elastic.Apm.AspNetFullFramework.Tests/Elastic.Apm.AspNetFullFramework.Tests.csproj
dotnet sln remove sample/AspNetFullFrameworkSampleApp/AspNetFullFrameworkSampleApp.csproj
# shellcheck disable=SC2086
Expand Down
66 changes: 24 additions & 42 deletions .ci/linux/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,28 @@ set -euxo pipefail
# Remove Full Framework projects
.ci/linux/remove-projects.sh

# Configure the projects for coverage and testing
while IFS= read -r -d '' file
do
if [[ $file == *"AspNetFullFrameworkSampleApp.csproj"* ]]; then
continue
fi
if [[ $file == *"Elastic.Apm.AspNetFullFramework.csproj"* ]]; then
continue
fi
if [[ $file == *"Elastic.Apm.AspNetFullFramework.Tests.csproj"* ]]; then
continue
fi
dotnet add "$file" package JunitXml.TestLogger --version 2.1.15
done < <(find . -name '*.csproj' -print0)
# Run tests for all solution
dotnet test -c Release ElasticApmAgent.sln \
--verbosity normal \
--results-directory target \
--diag "target/diag-ElasticApmAgent.log" \
--logger:"junit;LogFilePath=junit-{framework}-{assembly}.xml;MethodFormat=Class;FailureBodyFormat=Verbose" \
--collect:"XPlat Code Coverage" \
--settings coverlet.runsettings \
/p:CollectCoverage=true \
/p:CoverletOutputFormat=cobertura \
/p:CoverletOutput=target/Coverage/ \
/p:Threshold=0 \
/p:ThresholdType=branch \
/p:ThresholdStat=total \
|| echo -e "\033[31;49mTests FAILED\033[0m"

# Run tests per project to generate the coverage report individually.
while IFS= read -r -d '' file
do
projectName=$(basename "$file")
dotnet test "$file" \
--verbosity normal \
--results-directory target \
--diag "target/diag-${projectName}.log" \
--logger:"junit;LogFilePath=junit-{framework}-{assembly}.xml;MethodFormat=Class;FailureBodyFormat=Verbose" \
--collect:"XPlat Code Coverage" \
--settings coverlet.runsettings \
/p:CollectCoverage=true \
/p:CoverletOutputFormat=cobertura \
/p:CoverletOutput=target/Coverage/ \
/p:Threshold=0 \
/p:ThresholdType=branch \
/p:ThresholdStat=total \
|| echo -e "\033[31;49mTests FAILED\033[0m"

echo 'Move coverage files if they were generated!'
if [ -d target ] ; then
find target -type f -name 'coverage.cobertura.xml' |
while IFS= read -r fileName; do
target=$(dirname "$fileName")
mv "$fileName" "${target}/${projectName}-${fileName##*\/}"
done
fi
done < <(find test -name '*.csproj' -print0)
echo 'Move coverage files if they were generated!'
if [ -d target ] ; then
find target -type f -name 'coverage.cobertura.xml' |
while IFS= read -r fileName; do
target=$(dirname "$fileName")
parent=$(basename "$target")
mv "$fileName" "${target}/${parent}-${fileName##*\/}"
done
fi
2 changes: 1 addition & 1 deletion .ci/windows/dotnet.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ dotnet sln remove test/Elastic.Apm.AspNetFullFramework.Tests/Elastic.Apm.AspNetF
dotnet sln remove test/Elastic.Apm.SqlClient.Tests/Elastic.Apm.SqlClient.Tests.csproj
dotnet sln remove test/Elastic.Apm.EntityFramework6.Tests/Elastic.Apm.EntityFramework6.Tests.csproj

dotnet build --verbosity detailed
dotnet build -c Release --verbosity detailed
2 changes: 1 addition & 1 deletion .ci/windows/msbuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ echo "Prepare context for VsDevCmd.bat"
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\VsDevCmd.bat"
nuget restore -verbosity detailed -NonInteractive

msbuild
msbuild /p:Configuration=Release
7 changes: 5 additions & 2 deletions .ci/windows/test-iis.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ if not exist "%sample_app_log_dir%" mkdir "%sample_app_log_dir%"
icacls %sample_app_log_dir% /t /grant Everyone:F
set ELASTIC_APM_ASP_NET_FULL_FRAMEWORK_SAMPLE_APP_LOG_FILE=%sample_app_log_dir%\Elastic.Apm.AspNetFullFramework.Tests.SampleApp.log

dotnet test test\Elastic.Apm.AspNetFullFramework.Tests -v n -r target -d target\diag-iis.log --no-build ^
--logger:"junit;LogFilePath=junit-{framework}-{assembly}.xml;MethodFormat=Class;FailureBodyFormat=Verbose" ^
dotnet test -c Release test\Elastic.Apm.AspNetFullFramework.Tests --no-build ^
--verbosity normal ^
--results-directory target ^
--diag target\diag-iis.log ^
--logger:"junit;LogFilePath=junit-{framework}-{assembly}.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
2 changes: 1 addition & 1 deletion .ci/windows/test-tools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ dotnet tool install -g Codecov.Tool --version 1.2.0

Get-ChildItem -Path . -Recurse -Filter *.csproj |
Foreach-Object {
dotnet add $_.FullName package JunitXml.TestLogger --version 2.1.15
dotnet add $_.FullName package JunitXml.TestLogger --version 2.1.78
dotnet add $_.FullName package coverlet.msbuild --version 2.9.0
}
5 changes: 4 additions & 1 deletion .ci/windows/test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
:: This script runs the tests and stored them in an xml file defined in the
:: LogFilePath property
::
dotnet test -v n -r target -d target\diag.log --no-build ^
dotnet test -c Release --no-build ^
--verbosity normal ^
--results-directory target ^
--diag target\diag.log ^
--logger:"junit;LogFilePath=junit-{framework}-{assembly}.xml;MethodFormat=Class;FailureBodyFormat=Verbose" ^
/p:CollectCoverage=true ^
/p:CoverletOutputFormat=cobertura ^
Expand Down
2 changes: 1 addition & 1 deletion .ci/windows/testnet461.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:: This script runs the tests and stored them in an xml file defined in the
:: LogFilePath property
::
dotnet publish test\Elastic.Apm.Tests --framework net461 -o outtestnet461
dotnet publish -c Release test\Elastic.Apm.Tests --framework net461 -o outtestnet461

dotnet vstest outtestnet461\Elastic.Apm.Tests.dll ^
--logger:"junit;LogFilePath=test\junit-{framework}-{assembly}.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ The agent is designed to monitor production applications. Therefore it's very im

It's not uncommon that you write or change code that can potentially change the performance characteristics of the agent and therefore also of the application's of our users.

If this is the case then a perf. test should be added to the `test\Elastic.Apm.PerfTests` project which proves that the new code does not make the performance of the agent worse than it was before your PR.
If this is the case then a perf. test should be added to the `test\Elastic.Apm.Benchmarks` project which proves that the new code does not make the performance of the agent worse than it was before your PR.

We care both about memory and CPU overhead and both should be measured. The `test\Elastic.Apm.PerfTests` is configured to measure both.
We care both about memory and CPU overhead and both should be measured. The `test\Elastic.Apm.Benchmarks` is configured to measure both.

#### Compatibility

Expand Down
13 changes: 11 additions & 2 deletions ElasticApmAgent.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "files", "files", "{B406113B
build.bat = build.bat
build.sh = build.sh
dotnet-tools.json = dotnet-tools.json
xunit.runner.json = xunit.runner.json
coverlet.runsettings = coverlet.runsettings
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elastic.Apm.PerfTests", "test\Elastic.Apm.PerfTests\Elastic.Apm.PerfTests.csproj", "{F069CE99-F418-4BC2-9E44-8F03497D8DA8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elastic.Apm.Benchmarks", "test\Elastic.Apm.Benchmarks\Elastic.Apm.Benchmarks.csproj", "{F069CE99-F418-4BC2-9E44-8F03497D8DA8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetFullFrameworkSampleApp", "sample\AspNetFullFrameworkSampleApp\AspNetFullFrameworkSampleApp.csproj", "{C45DCD78-7E8A-437C-ABBB-01D154ABCFC4}"
EndProject
Expand All @@ -63,7 +65,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elastic.Apm.AspNetFullFrame
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elastic.Apm.EntityFramework6", "src\Elastic.Apm.EntityFramework6\Elastic.Apm.EntityFramework6.csproj", "{12FFCFF6-858C-4E6E-935C-E304712DECA4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elastic.Apm.DockerTests", "test\Elastic.Apm.DockerTests\Elastic.Apm.DockerTests.csproj", "{40B47FD4-6E67-4D52-B9A4-607B9D01D9F5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elastic.Apm.Docker.Tests", "test\Elastic.Apm.Docker.Tests\Elastic.Apm.Docker.Tests.csproj", "{40B47FD4-6E67-4D52-B9A4-607B9D01D9F5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elastic.Apm.AspNetFullFramework.Tests", "test\Elastic.Apm.AspNetFullFramework.Tests\Elastic.Apm.AspNetFullFramework.Tests.csproj", "{4253798D-A160-40B3-8F16-5BF64C559B93}"
EndProject
Expand Down Expand Up @@ -113,6 +115,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Apm.Specification",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Apm.AspNetCore.Static.Tests", "test\Elastic.Apm.AspNetCore.Static.Tests\Elastic.Apm.AspNetCore.Static.Tests.csproj", "{2250D888-E4CC-4B2B-AF31-5C78D76EC73D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Apm.Tests.Utilities", "test\Elastic.Apm.Tests.Utilities\Elastic.Apm.Tests.Utilities.csproj", "{43F9247D-544B-49FB-9E50-FC236D90DE1A}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
test\Elastic.Apm.DatabaseTests.Common\Elastic.Apm.DatabaseTests.Common.projitems*{968e1e85-e996-42de-9845-d20dae16165a}*SharedItemsImports = 5
Expand Down Expand Up @@ -274,6 +278,10 @@ Global
{2250D888-E4CC-4B2B-AF31-5C78D76EC73D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2250D888-E4CC-4B2B-AF31-5C78D76EC73D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2250D888-E4CC-4B2B-AF31-5C78D76EC73D}.Release|Any CPU.Build.0 = Release|Any CPU
{43F9247D-544B-49FB-9E50-FC236D90DE1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43F9247D-544B-49FB-9E50-FC236D90DE1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43F9247D-544B-49FB-9E50-FC236D90DE1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43F9247D-544B-49FB-9E50-FC236D90DE1A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -317,6 +325,7 @@ Global
{CB623206-F69E-4004-8527-D4B971AA981A} = {B406113B-0917-4531-AFEE-66DDB952590F}
{5D076C7F-1F8B-4B11-9910-48717D133963} = {3734A52F-2222-454B-BF58-1BA5C1F29D77}
{2250D888-E4CC-4B2B-AF31-5C78D76EC73D} = {267A241E-571F-458F-B04C-B6C4DE79E735}
{43F9247D-544B-49FB-9E50-FC236D90DE1A} = {267A241E-571F-458F-B04C-B6C4DE79E735}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {69E02FD9-C9DE-412C-AB6B-5B8BECC6BFA5}
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pipeline {

// Look for changes related to the benchmark, if so then set the env variable.
def patternList = [
'^test/Elastic.Apm.PerfTests/.*'
'^test/Elastic.Apm.Benchmarks/.*'
]
env.BENCHMARK_UPDATED = isGitRegionMatch(patterns: patternList)
}
Expand Down
9 changes: 5 additions & 4 deletions coverlet.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>cobertura</Format>
<Exclude>"[Elastic.Apm.Tests]*,[SampleAspNetCoreApp*]*,[xunit*]*"</Exclude>
<Format>cobertura</Format>
<Include>[Elastic.*]*,[ElasticApmStartupHook]*</Include>
<Exclude>[Elastic.Apm.Tests]*,[Elastic.Apm.*.Tests]*,[Elastic.Apm.Tests.*]*,[Elastic.Apm.Benchmarks]*</Exclude>
<SingleHit>false</SingleHit>
<UseSourceLink>true</UseSourceLink>
<IncludeTestAssembly>true</IncludeTestAssembly>
<UseSourceLink>false</UseSourceLink>
<IncludeTestAssembly>false</IncludeTestAssembly>
</Configuration>
</DataCollector>
</DataCollectors>
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Apm.AspNetCore/ApmMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"Elastic.Apm.AspNetCore.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051df3e4d8341d66c6dfbf35b2fda3627d08073156ed98eef81122b94e86ef2e44e7980202d21826e367db9f494c265666ae30869fb4cd1a434d171f6b634aa67fa8ca5b9076d55dc3baa203d3a23b9c1296c9f45d06a45cf89520bef98325958b066d8c626db76dd60d0508af877580accdd0e9f88e46b6421bf09a33de53fe1")]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.PerfTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051df3e4d8341d66c6dfbf35b2fda3627d08073156ed98eef81122b94e86ef2e44e7980202d21826e367db9f494c265666ae30869fb4cd1a434d171f6b634aa67fa8ca5b9076d55dc3baa203d3a23b9c1296c9f45d06a45cf89520bef98325958b066d8c626db76dd60d0508af877580accdd0e9f88e46b6421bf09a33de53fe1")]
"Elastic.Apm.Benchmarks, PublicKey=002400000480000094000000060200000024000052534131000400000100010051df3e4d8341d66c6dfbf35b2fda3627d08073156ed98eef81122b94e86ef2e44e7980202d21826e367db9f494c265666ae30869fb4cd1a434d171f6b634aa67fa8ca5b9076d55dc3baa203d3a23b9c1296c9f45d06a45cf89520bef98325958b066d8c626db76dd60d0508af877580accdd0e9f88e46b6421bf09a33de53fe1")]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.Grpc.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051df3e4d8341d66c6dfbf35b2fda3627d08073156ed98eef81122b94e86ef2e44e7980202d21826e367db9f494c265666ae30869fb4cd1a434d171f6b634aa67fa8ca5b9076d55dc3baa203d3a23b9c1296c9f45d06a45cf89520bef98325958b066d8c626db76dd60d0508af877580accdd0e9f88e46b6421bf09a33de53fe1")]
Expand Down
20 changes: 10 additions & 10 deletions src/Elastic.Apm/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
using Elastic.Apm.Report;

//TODO: It'd be nice to move this into the .csproj
// Moq library uses CastleProxy to build mocks, which generates temporary assembly DynamicProxyGenAssembly2.
[assembly:
InternalsVisibleTo(
"DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.Extensions.Hosting, PublicKey=" + Signing.PublicKey)]
Expand Down Expand Up @@ -47,19 +51,16 @@
"Elastic.Apm.AspNetCore.Static.Tests, PublicKey=" + Signing.PublicKey)]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.NetCoreAll, PublicKey=" + Signing.PublicKey)]
"Elastic.Apm.Benchmarks, PublicKey=" + Signing.PublicKey)]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.NetCoreAll.Tests, PublicKey=" + Signing.PublicKey)]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.PerfTests, PublicKey=" + Signing.PublicKey)]
"Elastic.Apm.Docker.Tests, PublicKey=" + Signing.PublicKey)]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.AspNetFullFramework, PublicKey=" + Signing.PublicKey)]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.DockerTests, PublicKey=" + Signing.PublicKey)]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.AspNetFullFramework.Tests, PublicKey=" + Signing.PublicKey)]
Expand All @@ -72,10 +73,6 @@
[assembly:
InternalsVisibleTo(
"Elastic.Apm.Elasticsearch.Tests, PublicKey=" + Signing.PublicKey)]
// Moq library uses CastleProxy to build mocks, which generates temporary assembly DynamicProxyGenAssembly2.
[assembly:
InternalsVisibleTo(
"DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.Feature.Tests, PublicKey=" + Signing.PublicKey)]
Expand All @@ -90,13 +87,16 @@
"Elastic.Apm.Grpc.Tests, PublicKey=" + Signing.PublicKey)]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.Specification, PublicKey=" + Signing.PublicKey)]
"Elastic.Apm.Specification, PublicKey=" + Signing.PublicKey)]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.StackExchange.Redis, PublicKey=" + Signing.PublicKey)]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.StackExchange.Redis.Tests, PublicKey=" + Signing.PublicKey)]
[assembly:
InternalsVisibleTo(
"Elastic.Apm.Tests.Utilities, PublicKey=" + Signing.PublicKey)]

internal static class Signing
{
Expand Down
6 changes: 3 additions & 3 deletions src/Elastic.Apm/BackendComm/BackendCommComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ private async Task WorkLoop()

await ExceptionUtils.DoSwallowingExceptions(_logger, async () =>
{
while (true) await WorkLoopIteration().ConfigureAwait(false);
while (!CancellationTokenSource.IsCancellationRequested)
await WorkLoopIteration().ConfigureAwait(false);
// ReSharper disable once FunctionNeverReturns
}
, dbgCallerMethodName: ThisClassName + "." + DbgUtils.CurrentMethodName()).ConfigureAwait(false);
Expand All @@ -106,13 +107,12 @@ public void Dispose()
_disposableHelper.DoOnce(_logger, _dbgName, () =>
{
_logger.Debug()?.Log("Calling CancellationTokenSource.Cancel()...");
// ReSharper disable once AccessToDisposedClosure
CancellationTokenSource.Cancel();
_logger.Debug()?.Log("Called CancellationTokenSource.Cancel()");

_logger.Debug()
?.Log("Waiting for loop to exit... Is cancellation token signaled: {IsCancellationRequested}",
CancellationTokenSource.Token.IsCancellationRequested);
CancellationTokenSource.IsCancellationRequested);
_loopCompleted.Wait();

_logger.Debug()?.Log("Disposing _singleThreadTaskScheduler ...");
Expand Down
18 changes: 11 additions & 7 deletions src/Elastic.Apm/Metrics/MetricsCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,19 @@ private List<MetricSample> CollectMetricsFromProviders()

public void Dispose()
{
if (MetricsProviders == null) return;

_timer?.Stop();
_timer?.Dispose();
if (_timer != null)
{
_timer.Stop();
_timer.Dispose();
}

foreach (var provider in MetricsProviders)
if (MetricsProviders != null)
{
if (provider is IDisposable disposable)
disposable.Dispose();
foreach (var provider in MetricsProviders)
{
if (provider is IDisposable disposable)
disposable.Dispose();
}
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,27 @@
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
<!-- Always generate debug symbols this allows fluent symbols exception messages to include variable names -->
<DebugSymbols>True</DebugSymbols>
<!-- All projects in this directory are assumed to be Test projects by default i.e. containing tests. Some may not
be however, so they can override this setting so that common test components are not added.
-->
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<!-- use xunit config for all test files. Allow assemblies to run in parallel -->
<Content Include="$(SolutionRoot)/xunit.runner.json" CopyToOutputDirectory="PreserveNewest" Condition="'$(IsTestProject)' == 'true'" />
</ItemGroup>

<ItemGroup>
<!-- Add coverlet MSBuild only for Windows -->
<PackageReference Include="coverlet.msbuild" Version="2.9.0" Condition="'$(IsTestProject)' == 'true' AND '$(OS)' == 'WINDOWS_NT'">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<!-- Add coverlet collector for all platforms -->
<PackageReference Include="coverlet.collector" Version="1.3.0" Condition="'$(IsTestProject)' == 'true'">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="JunitXml.TestLogger" Version="2.1.78" Condition="'$(IsTestProject)' == 'true'" />
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions test/Elastic.Apm.AspNetCore.Static.Tests/ConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
using Elastic.Apm.AspNetCore.Tests;
using Elastic.Apm.Config;
using Elastic.Apm.Extensions.Hosting.Config;
using Elastic.Apm.Tests.Mocks;
using Elastic.Apm.Tests.TestHelpers;
using Elastic.Apm.Tests.Utilities;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
Expand Down
Loading

0 comments on commit 5fa5a36

Please sign in to comment.