-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
correctness_test.go
154 lines (136 loc) · 4.47 KB
/
correctness_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
145
146
147
148
149
150
151
152
153
154
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package traces
import (
"fmt"
"log"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/open-telemetry/opentelemetry-collector-contrib/testbed/correctnesstests"
"github.com/open-telemetry/opentelemetry-collector-contrib/testbed/testbed"
)
var correctnessResults testbed.TestResultsSummary = &testbed.CorrectnessResults{}
func TestMain(m *testing.M) {
testbed.DoTestMain(m, correctnessResults)
}
func TestTracingGoldenData(t *testing.T) {
tests, err := correctnesstests.LoadPictOutputPipelineDefs("testdata/generated_pict_pairs_traces_pipeline.txt")
require.NoError(t, err)
processors := map[string]string{
"batch": `
batch:
send_batch_size: 1024
`,
}
for _, test := range tests {
test.TestName = fmt.Sprintf("%s-%s", test.Receiver, test.Exporter)
test.DataSender = correctnesstests.ConstructTraceSender(t, test.Receiver)
test.DataReceiver = correctnesstests.ConstructReceiver(t, test.Exporter)
t.Run(test.TestName, func(t *testing.T) {
testWithTracingGoldenDataset(t, test.DataSender, test.DataReceiver, test.ResourceSpec, processors)
})
}
}
func testWithTracingGoldenDataset(
t *testing.T,
sender testbed.DataSender,
receiver testbed.DataReceiver,
resourceSpec testbed.ResourceSpec,
processors map[string]string,
) {
dataProvider := testbed.NewGoldenDataProvider(
"../../../internal/coreinternal/goldendataset/testdata/generated_pict_pairs_traces.txt",
"../../../internal/coreinternal/goldendataset/testdata/generated_pict_pairs_spans.txt",
"")
factories, err := testbed.Components()
require.NoError(t, err, "default components resulted in: %v", err)
runner := testbed.NewInProcessCollector(factories)
validator := testbed.NewCorrectTestValidator(sender.ProtocolName(), receiver.ProtocolName(), dataProvider)
config := correctnesstests.CreateConfigYaml(sender, receiver, processors, "traces")
log.Println(config)
configCleanup, cfgErr := runner.PrepareConfig(config)
require.NoError(t, cfgErr, "collector configuration resulted in: %v", cfgErr)
defer configCleanup()
tc := testbed.NewTestCase(
t,
dataProvider,
sender,
receiver,
runner,
validator,
correctnessResults,
testbed.WithResourceLimits(resourceSpec),
)
defer tc.Stop()
tc.EnableRecording()
tc.StartBackend()
tc.StartAgent()
tc.StartLoad(testbed.LoadOptions{
DataItemsPerSecond: 1024,
ItemsPerBatch: 1,
})
tc.Sleep(2 * time.Second)
tc.StopLoad()
tc.WaitForN(func() bool { return tc.LoadGenerator.DataItemsSent() == tc.MockBackend.DataItemsReceived() },
3*time.Second, "all data items received")
tc.StopAgent()
tc.ValidateData()
}
func TestSporadicGoldenDataset(t *testing.T) {
testCases := []struct {
decisionFunc func() error
}{
{
decisionFunc: testbed.RandomNonPermanentError,
},
{
decisionFunc: testbed.RandomPermanentError,
},
}
for _, tt := range testCases {
factories, err := testbed.Components()
require.NoError(t, err, "default components resulted in: %v", err)
runner := testbed.NewInProcessCollector(factories)
options := testbed.LoadOptions{DataItemsPerSecond: 10000, ItemsPerBatch: 10}
dataProvider := testbed.NewGoldenDataProvider(
"../../../internal/coreinternal/goldendataset/testdata/generated_pict_pairs_traces.txt",
"../../../internal/coreinternal/goldendataset/testdata/generated_pict_pairs_spans.txt",
"")
sender := testbed.NewOTLPTraceDataSender(testbed.DefaultHost, testbed.GetAvailablePort(t))
receiver := testbed.NewOTLPDataReceiver(testbed.GetAvailablePort(t))
receiver.WithRetry(`
retry_on_failure:
enabled: false
`)
receiver.WithQueue(`
sending_queue:
enabled: false
`)
_, err = runner.PrepareConfig(correctnesstests.CreateConfigYaml(sender, receiver, nil, "traces"))
require.NoError(t, err, "collector configuration resulted in: %v", err)
validator := testbed.NewCorrectTestValidator(sender.ProtocolName(), receiver.ProtocolName(), dataProvider)
tc := testbed.NewTestCase(
t,
dataProvider,
sender,
receiver,
runner,
validator,
correctnessResults,
testbed.WithSkipResults(),
testbed.WithDecisionFunc(tt.decisionFunc),
)
defer tc.Stop()
tc.StartBackend()
tc.StartAgent()
tc.StartLoad(options)
tc.Sleep(3 * time.Second)
tc.StopLoad()
tc.WaitForN(func() bool {
return tc.LoadGenerator.DataItemsSent()-tc.LoadGenerator.PermanentErrors() == tc.MockBackend.DataItemsReceived()
}, 5*time.Second, "all data items received")
tc.StopAgent()
tc.ValidateData()
}
}