Skip to content

Commit 7c531f5

Browse files
committed
Check ping file
1 parent 770db47 commit 7c531f5

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

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

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

378+
var pingFile = reportFile.GetPingFile();
379+
File.Exists(pingFile.Path).Should().BeTrue();
378380
File.Exists(reportFile.Path).Should().BeTrue();
379381
}
380382

@@ -426,6 +428,8 @@ public async Task CheckThreadName()
426428
helper.StandardOutput.Should().Contain(CrashReportExpectedOutput);
427429
}
428430

431+
var pingFile = reportFile.GetPingFile();
432+
File.Exists(pingFile.Path).Should().BeTrue();
429433
File.Exists(reportFile.Path).Should().BeTrue();
430434
}
431435

@@ -503,7 +507,9 @@ public async Task OptionallyDoNotReportNonDatadogCrashes(bool mainThread)
503507
.And.EndWith("Crashing...\n"); // Making sure there is no additional output
504508
}
505509

506-
// TODO check for ping file
510+
var pingFile = reportFile.GetPingFile();
511+
// Ping should always be present, even if the crash is not reported
512+
File.Exists(pingFile.Path).Should().BeTrue();
507513
File.Exists(reportFile.Path).Should().BeFalse();
508514
}
509515

@@ -527,6 +533,8 @@ public async Task ReportNonDatadogCrashes()
527533
helper.StandardOutput.Should().Contain(CrashReportUnfilteredExpectedOutput);
528534
}
529535

536+
var pingFile = reportFile.GetPingFile();
537+
File.Exists(pingFile.Path).Should().BeTrue();
530538
File.Exists(reportFile.Path).Should().BeTrue();
531539
}
532540

@@ -550,6 +558,8 @@ public async Task MakeSureNonDatadogCrashesAreReportedByDefault()
550558
helper.StandardOutput.Should().Contain(CrashReportUnfilteredExpectedOutput);
551559
}
552560

561+
var pingFile = reportFile.GetPingFile();
562+
File.Exists(pingFile.Path).Should().BeTrue();
553563
File.Exists(reportFile.Path).Should().BeTrue();
554564
}
555565

@@ -568,10 +578,11 @@ public async Task ReportedStacktrace()
568578

569579
await helper.Task;
570580

581+
using var pingFile = reportFile.GetPingFile();
582+
File.Exists(pingFile.Path).Should().BeTrue();
571583
File.Exists(reportFile.Path).Should().BeTrue();
572584

573585
var reader = new StringReader(helper.StandardOutput);
574-
575586
int? mainThreadId = null;
576587
var expectedCallstack = new List<string>();
577588

@@ -596,12 +607,22 @@ public async Task ReportedStacktrace()
596607
mainThreadId.Should().NotBeNull();
597608
expectedCallstack.Should().HaveCountGreaterOrEqualTo(2);
598609

599-
var report = JObject.Parse(reportFile.GetContent());
610+
{
611+
var report = JObject.Parse(reportFile.GetContent());
612+
using var assertionScope = new AssertionScope();
613+
assertionScope.AddReportable("Report", report.ToString());
614+
615+
ValidateStacktrace(report["error"]["stack"]);
616+
}
600617

601618
using var assertionScope = new AssertionScope();
602-
assertionScope.AddReportable("Report", report.ToString());
619+
assertionScope.AddReportable("Ping", pingFile.GetContent());
620+
var pingFileContent = pingFile.GetContent();
621+
var ping = JObject.Parse(pingFileContent);
622+
ping["type"].Value<string>().Should().Be("Crash ping");
623+
ping["crash_uuid"].Value<string>().Should().NotBeNull();
603624

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

606627
void ValidateStacktrace(JToken callstack)
607628
{
@@ -756,5 +777,24 @@ public void Dispose()
756777
{
757778
File.Delete(Path);
758779
}
780+
781+
public TemporaryFile GetPingFile()
782+
{
783+
var filename = System.IO.Path.GetFileNameWithoutExtension(Path);
784+
var directory = System.IO.Path.GetDirectoryName(Path);
785+
var pingFile = $"{filename}-ping.json";
786+
787+
if (directory == null)
788+
{
789+
return new TemporaryFile(pingFile);
790+
}
791+
792+
return new TemporaryFile(Path.Combine(directory, pingFile));
793+
}
794+
795+
private TemporaryFile(string filePath)
796+
{
797+
Path = filePath;
798+
}
759799
}
760800
}

0 commit comments

Comments
 (0)