Skip to content

Commit 9bce9c0

Browse files
committed
fix ServiceNameCollector singleton
we save the original instance before replaced by mock to restore it Some tests rely on having. the original, and depending on the order the class my keep the mocks instead resulting in errors
1 parent 76ff002 commit 9bce9c0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

dd-trace-core/src/test/groovy/datadog/trace/core/taginterceptor/TagInterceptorTest.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ class TagInterceptorTest extends DDCoreSpecification {
696696
}
697697

698698
void "when interceptServiceName extraServiceProvider is called"() {
699+
def origServiceNameCollector = ServiceNameCollector.INSTANCE
699700
setup:
700701
final extraServiceProvider = Mock(ServiceNameCollector)
701702
ServiceNameCollector.INSTANCE = extraServiceProvider
@@ -708,9 +709,13 @@ class TagInterceptorTest extends DDCoreSpecification {
708709

709710
then:
710711
1 * extraServiceProvider.addService("some-service")
712+
713+
cleanup:
714+
ServiceNameCollector.INSTANCE = origServiceNameCollector
711715
}
712716

713717
void "when interceptServletContext extraServiceProvider is called"() {
718+
def origServiceNameCollector = ServiceNameCollector.INSTANCE
714719
setup:
715720
final extraServiceProvider = Mock(ServiceNameCollector)
716721
ServiceNameCollector.INSTANCE = extraServiceProvider
@@ -724,6 +729,9 @@ class TagInterceptorTest extends DDCoreSpecification {
724729
then:
725730
1 * extraServiceProvider.addService(expected)
726731

732+
cleanup:
733+
ServiceNameCollector.INSTANCE = origServiceNameCollector
734+
727735
where:
728736
value | expected
729737
"/" | "root-servlet"

internal-api/src/test/groovy/datadog/trace/api/naming/ExtraServiceProviderNamingV0ForkedTest.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import datadog.trace.api.remoteconfig.ServiceNameCollector
77
class ExtraServiceProviderNamingV0ForkedTest extends DDSpecification {
88

99
void "Naming schema calls ExtraServicesProvider if provides a service name"() {
10+
def origServiceNameCollector = ServiceNameCollector.INSTANCE
1011
setup:
1112
final extraServiceProvider = Mock(ServiceNameCollector)
1213
ServiceNameCollector.INSTANCE = extraServiceProvider
@@ -67,5 +68,8 @@ class ExtraServiceProviderNamingV0ForkedTest extends DDSpecification {
6768

6869
then:
6970
1 * extraServiceProvider.addService("anything")
71+
72+
cleanup:
73+
ServiceNameCollector.INSTANCE = origServiceNameCollector
7074
}
7175
}

0 commit comments

Comments
 (0)