mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-23 08:33:45 +01:00
97e10e440c
Fix leaked server connections close unused connections in the client lib close deprecated connection in the server lib The Server Picker is reusable in the guard if we want in the future. So we can support the server address changes. --------- Co-authored-by: Maycon Santos <mlsmaycon@gmail.com> * Add logging --------- Co-authored-by: Maycon Santos <mlsmaycon@gmail.com>
86 lines
1.5 KiB
Go
86 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"testing"
|
|
"time"
|
|
|
|
"go.opentelemetry.io/otel"
|
|
|
|
"github.com/netbirdio/netbird/relay/metrics"
|
|
)
|
|
|
|
type mockConn struct {
|
|
}
|
|
|
|
func (m mockConn) Read(b []byte) (n int, err error) {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockConn) Write(b []byte) (n int, err error) {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockConn) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func (m mockConn) LocalAddr() net.Addr {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockConn) RemoteAddr() net.Addr {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockConn) SetDeadline(t time.Time) error {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockConn) SetReadDeadline(t time.Time) error {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m mockConn) SetWriteDeadline(t time.Time) error {
|
|
//TODO implement me
|
|
panic("implement me")
|
|
}
|
|
|
|
func TestStore_DeletePeer(t *testing.T) {
|
|
s := NewStore()
|
|
|
|
m, _ := metrics.NewMetrics(context.Background(), otel.Meter(""))
|
|
|
|
p := NewPeer(m, []byte("peer_one"), nil, nil)
|
|
s.AddPeer(p)
|
|
s.DeletePeer(p)
|
|
if _, ok := s.Peer(p.String()); ok {
|
|
t.Errorf("peer was not deleted")
|
|
}
|
|
}
|
|
|
|
func TestStore_DeleteDeprecatedPeer(t *testing.T) {
|
|
s := NewStore()
|
|
|
|
m, _ := metrics.NewMetrics(context.Background(), otel.Meter(""))
|
|
|
|
conn := &mockConn{}
|
|
p1 := NewPeer(m, []byte("peer_id"), conn, nil)
|
|
p2 := NewPeer(m, []byte("peer_id"), conn, nil)
|
|
|
|
s.AddPeer(p1)
|
|
s.AddPeer(p2)
|
|
s.DeletePeer(p1)
|
|
|
|
if _, ok := s.Peer(p2.String()); !ok {
|
|
t.Errorf("second peer was deleted")
|
|
}
|
|
}
|