forked from newrelic/go-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinternal_txn_test.go
144 lines (140 loc) · 3.74 KB
/
internal_txn_test.go
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
132
133
134
135
136
137
138
139
140
141
142
143
144
package newrelic
import (
"testing"
"time"
"github.com/nedscode/go-agent/internal"
"github.com/nedscode/go-agent/internal/cat"
)
func TestShouldSaveTrace(t *testing.T) {
for _, tc := range []struct {
name string
expected bool
synthetics bool
tracerEnabled bool
collectTraces bool
duration time.Duration
threshold time.Duration
}{
{
name: "insufficient duration, all disabled",
expected: false,
synthetics: false,
tracerEnabled: false,
collectTraces: false,
duration: 1 * time.Second,
threshold: 2 * time.Second,
},
{
name: "insufficient duration, only synthetics enabled",
expected: true,
synthetics: true,
tracerEnabled: false,
collectTraces: false,
duration: 1 * time.Second,
threshold: 2 * time.Second,
},
{
name: "insufficient duration, only tracer enabled",
expected: false,
synthetics: false,
tracerEnabled: true,
collectTraces: false,
duration: 1 * time.Second,
threshold: 2 * time.Second,
},
{
name: "insufficient duration, only collect traces enabled",
expected: false,
synthetics: false,
tracerEnabled: false,
collectTraces: true,
duration: 1 * time.Second,
threshold: 2 * time.Second,
},
{
name: "insufficient duration, all normal flags enabled",
expected: false,
synthetics: false,
tracerEnabled: true,
collectTraces: true,
duration: 1 * time.Second,
threshold: 2 * time.Second,
},
{
name: "insufficient duration, all flags enabled",
expected: true,
synthetics: true,
tracerEnabled: true,
collectTraces: true,
duration: 1 * time.Second,
threshold: 2 * time.Second,
},
{
name: "sufficient duration, all disabled",
expected: false,
synthetics: false,
tracerEnabled: false,
collectTraces: false,
duration: 3 * time.Second,
threshold: 2 * time.Second,
},
{
name: "sufficient duration, only synthetics enabled",
expected: true,
synthetics: true,
tracerEnabled: false,
collectTraces: false,
duration: 3 * time.Second,
threshold: 2 * time.Second,
},
{
name: "sufficient duration, only tracer enabled",
expected: false,
synthetics: false,
tracerEnabled: true,
collectTraces: false,
duration: 3 * time.Second,
threshold: 2 * time.Second,
},
{
name: "sufficient duration, only collect traces enabled",
expected: false,
synthetics: false,
tracerEnabled: false,
collectTraces: true,
duration: 3 * time.Second,
threshold: 2 * time.Second,
},
{
name: "sufficient duration, all normal flags enabled",
expected: true,
synthetics: false,
tracerEnabled: true,
collectTraces: true,
duration: 3 * time.Second,
threshold: 2 * time.Second,
},
{
name: "sufficient duration, all flags enabled",
expected: true,
synthetics: true,
tracerEnabled: true,
collectTraces: true,
duration: 3 * time.Second,
threshold: 2 * time.Second,
},
} {
txn := &txn{}
txn.Config.TransactionTracer.Enabled = tc.tracerEnabled
txn.Config.TransactionTracer.Threshold.Duration = tc.threshold
txn.Reply = &internal.ConnectReply{CollectTraces: tc.collectTraces}
txn.Duration = tc.duration
if tc.synthetics {
txn.CrossProcess.Synthetics = &cat.SyntheticsHeader{}
txn.CrossProcess.SetSynthetics(tc.synthetics)
}
if actual := txn.shouldSaveTrace(); actual != tc.expected {
t.Errorf("%s: unexpected shouldSaveTrace value; expected %v; got %v", tc.name, tc.expected, actual)
}
}
}