-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from dv00d00/timing-fixes-for-buffered-formatter
when formatting timing use miliseconds instead of ticks
- Loading branch information
Showing
2 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/JustEat.StatsD.Tests/BufferBasedStatsDPublisherTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using JustEat.StatsD.Buffered; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace JustEat.StatsD | ||
{ | ||
public class BufferBasedStatsDPublisherTests | ||
{ | ||
private readonly FakeTransport _transport = new FakeTransport(); | ||
private readonly StatsDConfiguration _configuration = new StatsDConfiguration { Prefix = "test" }; | ||
private readonly BufferBasedStatsDPublisher _sut; | ||
|
||
public BufferBasedStatsDPublisherTests() | ||
{ | ||
_sut = new BufferBasedStatsDPublisher(_configuration, _transport); | ||
} | ||
|
||
[Fact] | ||
public void TestTiming_TimeSpan() | ||
{ | ||
_sut.Timing(TimeSpan.FromSeconds(1.234), "timing"); | ||
_transport.Messages.ShouldHaveSingleItem("test.timing:1234|ms"); | ||
} | ||
|
||
[Fact] | ||
public void TestTimingSampled_TimeSpan() | ||
{ | ||
for (int i = 0; _transport.Messages.Count == 0 && i < 10000; i++) | ||
{ | ||
_sut.Timing(TimeSpan.FromSeconds(1.234), 0.99, "timing"); | ||
} | ||
_transport.Messages.ShouldHaveSingleItem("test.timing:1234|ms|@0.99"); | ||
} | ||
|
||
[Fact] | ||
public void TestTiming_Long() | ||
{ | ||
_sut.Timing(1234, "timing"); | ||
_transport.Messages.ShouldHaveSingleItem("test.timing:1234|ms"); | ||
} | ||
|
||
[Fact] | ||
public void TestTimingSampled_Long() | ||
{ | ||
for (int i = 0; _transport.Messages.Count == 0 && i < 10000; i++) | ||
{ | ||
_sut.Timing(1234, 0.99, "timing"); | ||
} | ||
_transport.Messages.ShouldHaveSingleItem("test.timing:1234|ms|@0.99"); | ||
} | ||
|
||
private class FakeTransport : IStatsDBufferedTransport | ||
{ | ||
public List<string> Messages { get; } = new List<string>(); | ||
|
||
public void Send(in ArraySegment<byte> metric) | ||
{ | ||
Messages.Add(Encoding.UTF8.GetString(metric.Array, metric.Offset, metric.Count)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters