Skip to content

Commit 61b2c62

Browse files
committed
Check ping file
1 parent 770db47 commit 61b2c62

File tree

2 files changed

+60
-16
lines changed

2 files changed

+60
-16
lines changed

tracer/src/Datadog.Trace.Tools.dd_dotnet/CreatedumpCommand.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -832,17 +832,17 @@ private unsafe bool SendPing(ICrashReport crashReport, ClrRuntime runtime)
832832

833833
try
834834
{
835-
var filename = Path.GetFileNameWithoutExtension(outputFile);
836-
var directory = Path.GetDirectoryName(outputFile);
837-
var pingFile = $"{filename}-ping.json";
838-
if (directory == null)
839-
{
840-
outputFile = pingFile;
841-
}
842-
else
843-
{
844-
outputFile = Path.Combine(directory, pingFile);
845-
}
835+
Uri? uri;
836+
var hasScheme = Uri.TryCreate(outputFile, UriKind.Absolute, out uri);
837+
var pathToModify = hasScheme ? uri!.LocalPath : outputFile;
838+
839+
var directory = Path.GetDirectoryName(pathToModify);
840+
var filename = Path.GetFileNameWithoutExtension(pathToModify);
841+
var pingPath = Path.Combine(directory ?? string.Empty, $"{filename}-ping.json");
842+
843+
outputFile = hasScheme
844+
? new UriBuilder(uri!) { Path = pingPath }.Uri.AbsoluteUri
845+
: pingPath;
846846

847847
DebugPrint($"Writing crash ping to {outputFile}...");
848848
path = Marshal.StringToHGlobalAnsi(outputFile);

tracer/test/Datadog.Trace.Tools.dd_dotnet.ArtifactTests/CreatedumpTests.cs

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,10 @@ public async Task NativeCrash()
375375
helper.StandardOutput.Should().Contain(CrashReportExpectedOutput);
376376
}
377377

378+
using var pingFile = reportFile.GetPingFile();
379+
Output.WriteLine(pingFile.Url);
378380
File.Exists(reportFile.Path).Should().BeTrue();
381+
File.Exists(pingFile.Path).Should().BeTrue();
379382
}
380383

381384
[SkippableFact]
@@ -426,6 +429,9 @@ public async Task CheckThreadName()
426429
helper.StandardOutput.Should().Contain(CrashReportExpectedOutput);
427430
}
428431

432+
using var pingFile = reportFile.GetPingFile();
433+
Output.WriteLine(pingFile.Url);
434+
File.Exists(pingFile.Path).Should().BeTrue();
429435
File.Exists(reportFile.Path).Should().BeTrue();
430436
}
431437

@@ -496,14 +502,19 @@ public async Task OptionallyDoNotReportNonDatadogCrashes(bool mainThread)
496502

497503
await helper.Task;
498504

505+
using var pingFile = reportFile.GetPingFile();
506+
Output.WriteLine(pingFile.Url);
507+
499508
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
500509
{
501510
helper.StandardOutput.Should()
502511
.NotContain(CrashReportExpectedOutput)
503512
.And.EndWith("Crashing...\n"); // Making sure there is no additional output
504513
}
505514

506-
// TODO check for ping file
515+
// Ping should always be present, even if the crash is not reported
516+
File.Exists(pingFile.Path).Should().BeTrue();
517+
pingFile.GetContent().Should().BeEmpty();
507518
File.Exists(reportFile.Path).Should().BeFalse();
508519
}
509520

@@ -527,6 +538,8 @@ public async Task ReportNonDatadogCrashes()
527538
helper.StandardOutput.Should().Contain(CrashReportUnfilteredExpectedOutput);
528539
}
529540

541+
using var pingFile = reportFile.GetPingFile();
542+
File.Exists(pingFile.Path).Should().BeTrue();
530543
File.Exists(reportFile.Path).Should().BeTrue();
531544
}
532545

@@ -550,6 +563,9 @@ public async Task MakeSureNonDatadogCrashesAreReportedByDefault()
550563
helper.StandardOutput.Should().Contain(CrashReportUnfilteredExpectedOutput);
551564
}
552565

566+
using var pingFile = reportFile.GetPingFile();
567+
Output.WriteLine(pingFile.Url);
568+
File.Exists(pingFile.Path).Should().BeTrue();
553569
File.Exists(reportFile.Path).Should().BeTrue();
554570
}
555571

@@ -568,10 +584,12 @@ public async Task ReportedStacktrace()
568584

569585
await helper.Task;
570586

587+
using var pingFile = reportFile.GetPingFile();
588+
Output.WriteLine(pingFile.Url);
571589
File.Exists(reportFile.Path).Should().BeTrue();
590+
File.Exists(pingFile.Path).Should().BeTrue();
572591

573592
var reader = new StringReader(helper.StandardOutput);
574-
575593
int? mainThreadId = null;
576594
var expectedCallstack = new List<string>();
577595

@@ -597,11 +615,18 @@ public async Task ReportedStacktrace()
597615
expectedCallstack.Should().HaveCountGreaterOrEqualTo(2);
598616

599617
var report = JObject.Parse(reportFile.GetContent());
618+
using var reportAssertionScope = new AssertionScope();
619+
reportAssertionScope.AddReportable("Report", report.ToString());
620+
ValidateStacktrace(report["error"]["stack"]);
600621

601-
using var assertionScope = new AssertionScope();
602-
assertionScope.AddReportable("Report", report.ToString());
622+
using var pingAssertionScope = new AssertionScope();
623+
pingAssertionScope.AddReportable("Ping", pingFile.GetContent());
624+
var pingFileContent = pingFile.GetContent();
625+
var ping = JObject.Parse(pingFileContent);
626+
ping["type"].Value<string>().Should().Be("Crash ping");
627+
ping["crash_uuid"].Value<string>().Should().NotBeNull();
603628

604-
ValidateStacktrace(report["error"]["stack"]);
629+
pingFileContent.Should().BeEmpty();
605630

606631
void ValidateStacktrace(JToken callstack)
607632
{
@@ -744,6 +769,11 @@ public TemporaryFile()
744769
File.Delete(Path);
745770
}
746771

772+
private TemporaryFile(string filePath)
773+
{
774+
Path = filePath;
775+
}
776+
747777
public string Path { get; }
748778

749779
public string Url => $"file://{Path}";
@@ -756,5 +786,19 @@ public void Dispose()
756786
{
757787
File.Delete(Path);
758788
}
789+
790+
public TemporaryFile GetPingFile()
791+
{
792+
var filename = System.IO.Path.GetFileNameWithoutExtension(Path);
793+
var directory = System.IO.Path.GetDirectoryName(Path);
794+
var pingFile = $"{filename}-ping.json";
795+
796+
if (directory == null)
797+
{
798+
return new TemporaryFile(pingFile);
799+
}
800+
801+
return new TemporaryFile(System.IO.Path.Combine(directory, pingFile));
802+
}
759803
}
760804
}

0 commit comments

Comments
 (0)