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

Enable udp server tests #12919

Merged
merged 6 commits into from
Aug 4, 2022
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
9 changes: 8 additions & 1 deletion receiver/carbonreceiver/transport/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func Test_Server_ListenAndServe(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
addr := testutil.GetAvailableLocalAddress(t)
addr := testutil.GetAvailableLocalNetworkAddress(t, tt.name)

svr, err := tt.buildServerFn(addr)
require.NoError(t, err)
require.NotNil(t, svr)
Expand Down Expand Up @@ -89,6 +90,12 @@ func Test_Server_ListenAndServe(t *testing.T) {

mr.WaitAllOnMetricsProcessedCalls()

// Keep trying until we're timed out or got a result
assert.Eventually(t, func() bool {
mdd := mc.AllMetrics()
return len(mdd) > 0
}, 10*time.Second, 500*time.Millisecond)

err = svr.Close()
assert.NoError(t, err)

Expand Down
26 changes: 22 additions & 4 deletions receiver/statsdreceiver/transport/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"strconv"
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -31,7 +32,6 @@ import (
)

func Test_Server_ListenAndServe(t *testing.T) {
t.Skip("Test is unstable, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/1426")

tests := []struct {
name string
Expand All @@ -48,7 +48,21 @@ func Test_Server_ListenAndServe(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
addr := testutil.GetAvailableLocalAddress(t)
addr := testutil.GetAvailableLocalNetworkAddress(t, "udp")

// Endpoint should be free.
ln0, err := net.ListenPacket("udp", addr)
require.NoError(t, err)
require.NotNil(t, ln0)

// Ensure that the endpoint wasn't something like ":0" by checking that a second listener will fail.
ln1, err := net.ListenPacket("udp", addr)
require.Error(t, err)
require.Nil(t, ln1)

// Unbind the local address so the mock UDP service can use it
ln0.Close()

srv, err := tt.buildServerFn(addr)
require.NoError(t, err)
require.NotNil(t, srv)
Expand Down Expand Up @@ -76,18 +90,22 @@ func Test_Server_ListenAndServe(t *testing.T) {
gc, err := tt.buildClientFn(host, port)
require.NoError(t, err)
require.NotNil(t, gc)

err = gc.SendMetric(client.Metric{
Name: "test.metric",
Value: "42",
Type: "c",
})
assert.NoError(t, err)
runtime.Gosched()

err = gc.Disconnect()
assert.NoError(t, err)

// Keep trying until we're timed out or got a result
assert.Eventually(t, func() bool {
return len(transferChan) > 0
}, 10*time.Second, 500*time.Millisecond)

// Close the server connection, this will cause ListenAndServer to error out and the deferred wgListenAndServe.Done will fire
err = srv.Close()
assert.NoError(t, err)

Expand Down