-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy pathBaseHashTest.groovy
More file actions
131 lines (99 loc) · 3.39 KB
/
BaseHashTest.groovy
File metadata and controls
131 lines (99 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package datadog.trace.api
import static datadog.trace.api.config.GeneralConfig.ENV
import static datadog.trace.api.config.GeneralConfig.EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED
import static datadog.trace.api.config.GeneralConfig.PRIMARY_TAG
import static datadog.trace.api.config.GeneralConfig.SERVICE_NAME
import datadog.trace.test.util.DDSpecification
class BaseHashTest extends DDSpecification {
def setup() {
// start with fresh process tags
ProcessTags.reset()
}
def cleanup() {
// restore the default enablement
removeSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED)
ProcessTags.reset()
}
def "Service used in hash calculation"() {
when:
def firstBaseHash = BaseHash.calc(null)
injectSysConfig(SERVICE_NAME, "service-1")
def secondBaseHash = BaseHash.calc(null)
then:
firstBaseHash != secondBaseHash
}
def "Env used in hash calculation"() {
when:
def firstBaseHash = BaseHash.calc(null)
injectSysConfig(ENV, "env-1")
def secondBaseHash = BaseHash.calc(null)
then:
firstBaseHash != secondBaseHash
}
def "Primary tag used in hash calculation"() {
when:
def firstBaseHash = BaseHash.calc(null)
injectSysConfig(PRIMARY_TAG, "region-2")
def secondBaseHash = BaseHash.calc(null)
then:
firstBaseHash != secondBaseHash
}
def "Process Tags used in hash calculation"() {
when:
def firstBaseHash = BaseHash.calc(null)
ProcessTags.addTag("000", "first")
def secondBaseHash = BaseHash.calc(null)
then:
firstBaseHash != secondBaseHash
assert ProcessTags.getTagsForSerialization().startsWithAny("000:first,")
}
def "addTag triggers BaseHash recalculation"() {
given:
BaseHash.recalcBaseHash("container-hash-1")
def hashBefore = BaseHash.getBaseHash()
when:
ProcessTags.addTag("cluster.name", "new-cluster")
then:
BaseHash.getBaseHash() != hashBefore
}
def "recalcBaseHash preserves last containerTagsHash across ProcessTags changes"() {
given:
def containerHash = "my-container-hash"
BaseHash.recalcBaseHash(containerHash)
def hashWithContainerTag = BaseHash.getBaseHash()
when: "a process tag is added"
ProcessTags.addTag("cluster.name", "new-cluster")
then: "hash differs from before the tag was added"
BaseHash.getBaseHash() != hashWithContainerTag
and: "hash equals a fresh calc with the same container hash"
BaseHash.getBaseHash() == BaseHash.calc(containerHash)
}
def "addTag does not recalculate BaseHash when ProcessTags disabled"() {
setup:
injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "false")
ProcessTags.reset()
BaseHash.recalcBaseHash(null)
def hashBefore = BaseHash.getBaseHash()
when:
ProcessTags.addTag("cluster.name", "ignored")
then:
BaseHash.getBaseHash() == hashBefore
}
def "ContainerTagsHash used in hash calculation when provided"() {
when:
injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, propagateTagsEnabled.toString())
ProcessTags.reset()
ProcessTags.addTag("000", "first")
def firstBaseHash = BaseHash.calc(null)
then:
def secondBaseHash = BaseHash.calc("<test-container-tags-hash>")
expect:
if (propagateTagsEnabled) {
assert secondBaseHash != firstBaseHash
} else {
assert secondBaseHash == firstBaseHash
}
where:
propagateTagsEnabled << [true, false]
}
}