Skip to content
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

Run test assemblies in parallel #1106

Merged
merged 61 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
0df0260
Separate test components from Elastic.Apm.Tests
russcam Dec 30, 2020
8e73dce
Allow test assemblies to run in parallel
russcam Dec 30, 2020
3fb4b12
Remove unneeded using directives
russcam Dec 30, 2020
df941b1
Add coverlet and JunitXml.TestLogger with Directory.Build.Props
russcam Dec 30, 2020
b755699
Run tests for solution
russcam Dec 30, 2020
1bbc6ac
Exclude all test assemblies from code coverage
russcam Dec 30, 2020
8008173
Rename Elastic.Apm.DockerTests
russcam Dec 30, 2020
ee31ca6
Rename Elastic.Apm.PerfTests
russcam Dec 30, 2020
c9e5bd1
get parent directory name
russcam Dec 30, 2020
f23b044
Unregister GC event handlers and dispose session and task
russcam Dec 31, 2020
68834ef
Exclude System assemblies from coverage
russcam Dec 31, 2020
3d94c04
Update coverlet.collector and JUnitXml.TestLogger packages
russcam Dec 31, 2020
d7f5f02
Update Microsoft.NET.Test.Sdk
russcam Dec 31, 2020
925e8b7
Merge branch 'master' into test/sln-file
russcam Jan 4, 2021
b2439e0
Add XML docs to IConfigurationReader
russcam Jan 4, 2021
0a6b3ca
Remove Test SDK from utilities project
russcam Jan 4, 2021
0f97f06
Mark Perf.Tests not a test project
russcam Jan 4, 2021
12c874e
Update xunit, xunit.runner.visualstudio
russcam Jan 4, 2021
2f78d35
Merge branch 'master' into test/sln-file
russcam Jan 5, 2021
f44493a
Merge remote-tracking branch 'upstream/master'
russcam Jan 5, 2021
e216dcd
Merge branch 'master' into test/sln-file
russcam Jan 5, 2021
0ec4d26
Use TestAgentComponents in test
russcam Jan 5, 2021
d3e8d69
Add assertion
russcam Jan 5, 2021
0874d39
Merge remote-tracking branch 'upstream/master'
russcam Jan 5, 2021
4bb587a
dispose connection
russcam Jan 5, 2021
0dcf2f8
Include only Elastic.* assemblies for code coverage
russcam Jan 5, 2021
ae1c580
Merge branch 'master' into test/sln-file
russcam Jan 5, 2021
192d931
Run linux tests without code coverage
russcam Jan 5, 2021
2f114ad
Reinstate code coverage on linux tests
russcam Jan 5, 2021
e7a6218
Remove environment from tests
russcam Jan 5, 2021
ad3d914
Check cancellation in workloop
russcam Jan 5, 2021
cdd5669
disable xunit assembly parallelization
russcam Jan 6, 2021
4796356
skip gc metrics for now
russcam Jan 6, 2021
0b7d3e4
Dispose timer before checking and disposing providers
russcam Jan 6, 2021
8a1984f
Remove netcoreapp2.2 from tests
russcam Jan 6, 2021
9b91c20
Use TestAgentComponents
russcam Jan 6, 2021
14c4dcc
skip sampler tests
russcam Jan 6, 2021
1169dca
Merge branch 'master' into test/sln-file
russcam Jan 6, 2021
fc6e4da
unskip sampler tests
russcam Jan 6, 2021
ef002f2
unskip collect gc metrics
russcam Jan 6, 2021
917bd49
skip Elastic.Apm.Tests on Linux for now
russcam Jan 6, 2021
41e57f4
update filter
russcam Jan 6, 2021
53092f8
Remove filter, add diagnostic verbosity
russcam Jan 7, 2021
3e0db7f
stub APM server response in tests
russcam Jan 7, 2021
6691116
Add back netcoreapp2.2 tests
russcam Jan 7, 2021
0122924
verbosity normal
russcam Jan 7, 2021
3585b9b
parallelize test assemblies
russcam Jan 7, 2021
a3125c7
Disable nodereuse on linux tests
russcam Jan 7, 2021
dde2cd7
Use Release configuration
russcam Jan 7, 2021
001e536
Don't allow method to be inlined
russcam Jan 7, 2021
a4d0273
Remove netcoreapp2.2 from tests
russcam Jan 7, 2021
d4469d6
Rename Elastic.Apm.Perf.Tests
russcam Jan 12, 2021
9d3579c
Merge branch 'master' into test/sln-file
russcam Jan 12, 2021
4ef24ad
Increase log level switch timeout
russcam Jan 12, 2021
c939702
Update directives from merge
russcam Jan 12, 2021
f0363a8
Don't Use SourceLink in coverlet.settings
russcam Jan 12, 2021
27b5f6e
Revert "Don't Use SourceLink in coverlet.settings"
russcam Jan 13, 2021
138f5c8
Assert ETW session is deleted on dispose
russcam Jan 13, 2021
b45fd78
Assert on specific TraceEventSession name
russcam Jan 13, 2021
0a30e59
Don't Use SourceLink in coverlet.settings
russcam Jan 13, 2021
ae985d9
Merge branch 'master' into test/sln-file
russcam Jan 13, 2021
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
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