Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] fix flaky test for datadogreceiver server binding #24895

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions receiver/datadogreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
func TestCreateReceiver(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
cfg.(*Config).Endpoint = "http://localhost:0"

tReceiver, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, consumertest.NewNop())
assert.NoError(t, err)
Expand Down
3 changes: 3 additions & 0 deletions receiver/datadogreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

type datadogReceiver struct {
address string
config *Config
params receiver.CreateSettings
nextConsumer consumer.Traces
Expand Down Expand Up @@ -66,6 +67,8 @@ func (ddr *datadogReceiver) Start(_ context.Context, host component.Host) error
return fmt.Errorf("failed to create datadog listener: %w", err)
}

ddr.address = hln.Addr().String()

go func() {
if err := ddr.server.Serve(hln); err != nil && !errors.Is(err, http.ErrServerClosed) {
host.ReportFatalError(fmt.Errorf("error starting datadog receiver: %w", err))
Expand Down
7 changes: 5 additions & 2 deletions receiver/datadogreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
func TestDatadogReceiver_Lifecycle(t *testing.T) {

factory := NewFactory()
ddr, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), factory.CreateDefaultConfig(), consumertest.NewNop())
cfg := factory.CreateDefaultConfig()
cfg.(*Config).Endpoint = "localhost:0"
ddr, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, consumertest.NewNop())
assert.NoError(t, err, "Receiver should be created")

err = ddr.Start(context.Background(), componenttest.NewNopHost())
Expand All @@ -34,6 +36,7 @@ func TestDatadogReceiver_Lifecycle(t *testing.T) {

func TestDatadogServer(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.Endpoint = "localhost:0" // Using a randomly assigned address
dd, err := newDataDogReceiver(
cfg,
consumertest.NewNop(),
Expand Down Expand Up @@ -69,7 +72,7 @@ func TestDatadogServer(t *testing.T) {

req, err := http.NewRequest(
http.MethodPost,
fmt.Sprintf("http://%s/v0.7/traces", cfg.Endpoint),
fmt.Sprintf("http://%s/v0.7/traces", dd.(*datadogReceiver).address),
tc.op,
)
require.NoError(t, err, "Must not error when creating request")
Expand Down