diff --git a/tests/TraceClient.Tests/InstallIdTest.cs b/tests/TraceClient.Tests/InstallIdTest.cs index 4880c9a..56c0b01 100644 --- a/tests/TraceClient.Tests/InstallIdTest.cs +++ b/tests/TraceClient.Tests/InstallIdTest.cs @@ -347,6 +347,26 @@ public void Report_AnEventsOwnInstallTagWins() _server.Received.Single().Body); } + [Fact] + public void Report_AnEventsOwnInstallTagPastTheLimitDropsTheEventRatherThanFallingBack() + { + var log = new ConcurrentQueue(); + var client = new TraceClient(_server.BaseUrl, "MyGame", "1.2.3", key: "k", log: log.Enqueue, + installId: "configured"); + + client.Report("startup", tags: new Dictionary { { "install", new string('i', TraceClient.MaxLength + 1) } }); + client.Report("command", tags: new Dictionary { { "install", new string('i', TraceClient.MaxLength) } }); + client.Close(); + + // The event's own tag wins even when the server would reject it, so the + // configured ID is not sent in its place: the whole event is dropped. + Assert.Equal("[trace] dropped startup: tag install longer than " + TraceClient.MaxLength + " characters", + Assert.Single(log)); + Assert.Equal("{\"application\":\"MyGame\",\"name\":\"command\"," + + "\"tags\":{\"install\":\"" + new string('i', TraceClient.MaxLength) + "\",\"version\":\"1.2.3\"}}", + _server.Received.Single().Body); + } + [Fact] public void Report_ANullInstallTagDoesNotDisplaceTheConfiguredId() { diff --git a/tests/TraceClient.Tests/TraceClientTest.cs b/tests/TraceClient.Tests/TraceClientTest.cs index c1dd52c..d1e7668 100644 --- a/tests/TraceClient.Tests/TraceClientTest.cs +++ b/tests/TraceClient.Tests/TraceClientTest.cs @@ -632,6 +632,25 @@ public void Report_AnEmptyVersionTagStillWinsOverTheProgramVersion() _server.Received.Single().Body); } + [Fact] + public void Report_AnEventsOwnVersionTagPastTheLimitDropsTheEventRatherThanFallingBack() + { + var log = new ConcurrentQueue(); + var client = new TraceClient(_server.BaseUrl, "MyGame", "1.2.3", key: "k", log: log.Enqueue); + + client.Report("startup", tags: new Dictionary { { "version", new string('9', TraceClient.MaxLength + 1) } }); + client.Report("command", tags: new Dictionary { { "version", new string('9', TraceClient.MaxLength) } }); + client.Close(); + + // The event's own tag wins even when the server would reject it, so the + // program's version is not sent in its place: the whole event is dropped. + Assert.Equal("[trace] dropped startup: tag version longer than " + TraceClient.MaxLength + " characters", + Assert.Single(log)); + Assert.Equal("{\"application\":\"MyGame\",\"name\":\"command\"," + + "\"tags\":{\"version\":\"" + new string('9', TraceClient.MaxLength) + "\"}}", + _server.Received.Single().Body); + } + [Fact] public void Report_OnlyTheExactLowercaseVersionKeyCountsAsTheEventsOwn() {