mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-14 10:13:10 +02:00
a304e8280d
* port reconnecting udp client from jaeger-client-go * Fix precommit issues * Fix license check * Add initial value for max packet size * Fix for atomic usage on 386 arch * Modify reconnecting option to an affirmative * Add changelog entry * Dont hold rlock for writes Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
package jaeger
|
|
|
|
import (
|
|
"log"
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNewAgentClientUDPWithParamsBadHostport(t *testing.T) {
|
|
hostPort := "blahblah"
|
|
|
|
agentClient, err := newAgentClientUDP(agentClientUDPParams{
|
|
HostPort: hostPort,
|
|
})
|
|
|
|
assert.Error(t, err)
|
|
assert.Nil(t, agentClient)
|
|
}
|
|
|
|
func TestNewAgentClientUDPWithParams(t *testing.T) {
|
|
mockServer, err := newUDPListener()
|
|
require.NoError(t, err)
|
|
defer mockServer.Close()
|
|
|
|
agentClient, err := newAgentClientUDP(agentClientUDPParams{
|
|
HostPort: mockServer.LocalAddr().String(),
|
|
MaxPacketSize: 25000,
|
|
AttemptReconnecting: true,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, agentClient)
|
|
assert.Equal(t, 25000, agentClient.maxPacketSize)
|
|
|
|
if assert.IsType(t, &reconnectingUDPConn{}, agentClient.connUDP) {
|
|
assert.Equal(t, (*log.Logger)(nil), agentClient.connUDP.(*reconnectingUDPConn).logger)
|
|
}
|
|
|
|
assert.NoError(t, agentClient.Close())
|
|
}
|
|
|
|
func TestNewAgentClientUDPWithParamsDefaults(t *testing.T) {
|
|
mockServer, err := newUDPListener()
|
|
require.NoError(t, err)
|
|
defer mockServer.Close()
|
|
|
|
agentClient, err := newAgentClientUDP(agentClientUDPParams{
|
|
HostPort: mockServer.LocalAddr().String(),
|
|
AttemptReconnecting: true,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, agentClient)
|
|
assert.Equal(t, udpPacketMaxLength, agentClient.maxPacketSize)
|
|
|
|
if assert.IsType(t, &reconnectingUDPConn{}, agentClient.connUDP) {
|
|
assert.Equal(t, (*log.Logger)(nil), agentClient.connUDP.(*reconnectingUDPConn).logger)
|
|
}
|
|
|
|
assert.NoError(t, agentClient.Close())
|
|
}
|
|
|
|
func TestNewAgentClientUDPWithParamsReconnectingDisabled(t *testing.T) {
|
|
mockServer, err := newUDPListener()
|
|
require.NoError(t, err)
|
|
defer mockServer.Close()
|
|
|
|
agentClient, err := newAgentClientUDP(agentClientUDPParams{
|
|
HostPort: mockServer.LocalAddr().String(),
|
|
Logger: nil,
|
|
AttemptReconnecting: false,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, agentClient)
|
|
assert.Equal(t, udpPacketMaxLength, agentClient.maxPacketSize)
|
|
|
|
assert.IsType(t, &net.UDPConn{}, agentClient.connUDP)
|
|
|
|
assert.NoError(t, agentClient.Close())
|
|
}
|