Skip to content

Commit

Permalink
Merge pull request #172 from yousifh/skip-metrics
Browse files Browse the repository at this point in the history
Allow IEndpointSource to return null Endpoint
  • Loading branch information
martincostello committed Apr 8, 2019
2 parents 6112cc2 + b114ee3 commit d72b96c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/JustEat.StatsD/SocketTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ public void Send(in ArraySegment<byte> metric)
return;
}

var pool = GetPool(_endpointSource.GetEndpoint());
var endpoint = _endpointSource.GetEndpoint();
if (endpoint == null)
{
return;
}

var pool = GetPool(endpoint);
var socket = pool.PopOrCreate();

try
Expand Down
12 changes: 12 additions & 0 deletions tests/JustEat.StatsD.Tests/SocketTransportTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Net;
using JustEat.StatsD.EndpointLookups;
using Moq;
using Shouldly;
using Xunit;

Expand Down Expand Up @@ -72,6 +73,17 @@ public static void SocketTransportIsNoopForEmptyArray()
}
}

[Fact]
public static void SocketTransportIsNoopForNullEndpoint()
{
var endpointSource = Mock.Of<IEndPointSource>();

using (var transport = new SocketTransport(endpointSource, SocketProtocol.IP))
{
transport.Send("teststat:1|c");
}
}

private static IEndPointSource LocalStatsEndpoint()
{
return new SimpleEndpointSource(new IPEndPoint(IPAddress.Loopback, StatsDConfiguration.DefaultPort));
Expand Down

0 comments on commit d72b96c

Please sign in to comment.