-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
main_test.go
61 lines (56 loc) · 1.85 KB
/
main_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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package main
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/receiver/otlpreceiver"
"go.opentelemetry.io/collector/receiver/receivertest"
"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/common"
"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/traces"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
)
func TestGenerateTraces(t *testing.T) {
f := otlpreceiver.NewFactory()
sink := &consumertest.TracesSink{}
rCfg := f.CreateDefaultConfig()
endpoint := testutil.GetAvailableLocalAddress(t)
rCfg.(*otlpreceiver.Config).GRPC.NetAddr.Endpoint = endpoint
r, err := f.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), rCfg, sink)
require.NoError(t, err)
err = r.Start(context.Background(), componenttest.NewNopHost())
require.NoError(t, err)
defer func() {
require.NoError(t, r.Shutdown(context.Background()))
}()
cfg := &traces.Config{
Config: common.Config{
WorkerCount: 10,
Rate: 10,
TotalDuration: 10 * time.Second,
ReportingInterval: 10,
CustomEndpoint: endpoint,
Insecure: true,
UseHTTP: false,
Headers: nil,
ResourceAttributes: nil,
SkipSettingGRPCLogger: true,
},
NumTraces: 6000,
ServiceName: "foo",
StatusCode: "0",
LoadSize: 0,
Batch: true,
}
go func() {
err = traces.Start(cfg)
require.NoError(t, err)
}()
require.Eventually(t, func() bool {
return len(sink.AllTraces()) > 0
}, 10*time.Second, 100*time.Millisecond)
}