Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed May 9, 2023
1 parent 0434af5 commit ae0b645
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,37 @@ public static void SimulateTestRun(
string targetFrameworkName,
params TestResult[] testResults)
{
var testSettings = @$"
<?xml version=""1.0"" encoding=""utf-8""?>
<RunSettings>
<RunConfiguration>
<TargetFrameworkVersion>{targetFrameworkName}</TargetFrameworkVersion>
</RunConfiguration>
</RunSettings>
".Trim();
// lang=xml
var testSettings =
$"""
<RunSettings>
<RunConfiguration>
<TargetFrameworkVersion>{targetFrameworkName}</TargetFrameworkVersion>
</RunConfiguration>
</RunSettings>
""";

context.HandleTestRunStart(
new TestRunStartEventArgs(
new TestRunCriteria(new[] { testSuiteFilePath }, 1, true, testSettings)
)
);
context.HandleTestRunStart(new TestRunStartEventArgs(
new TestRunCriteria(new[] { testSuiteFilePath }, 1, true, testSettings)
));

foreach (var testResult in testResults)
context.HandleTestResult(new TestResultEventArgs(testResult));

context.HandleTestRunComplete(
new TestRunCompleteEventArgs(
new TestRunStatistics(new Dictionary<TestOutcome, long>
{
[TestOutcome.Passed] = testResults.Count(r => r.Outcome == TestOutcome.Passed),
[TestOutcome.Failed] = testResults.Count(r => r.Outcome == TestOutcome.Failed),
[TestOutcome.Skipped] = testResults.Count(r => r.Outcome == TestOutcome.Skipped),
[TestOutcome.None] = testResults.Count(r => r.Outcome == TestOutcome.None)
}),
false,
false,
null,
new Collection<AttachmentSet>(),
TimeSpan.FromSeconds(1.234)
)
);
context.HandleTestRunComplete(new TestRunCompleteEventArgs(
new TestRunStatistics(new Dictionary<TestOutcome, long>
{
[TestOutcome.Passed] = testResults.Count(r => r.Outcome == TestOutcome.Passed),
[TestOutcome.Failed] = testResults.Count(r => r.Outcome == TestOutcome.Failed),
[TestOutcome.Skipped] = testResults.Count(r => r.Outcome == TestOutcome.Skipped),
[TestOutcome.None] = testResults.Count(r => r.Outcome == TestOutcome.None)
}),
false,
false,
null,
new Collection<AttachmentSet>(),
TimeSpan.FromSeconds(1.234)
));
}

public static void SimulateTestRun(
Expand Down
3 changes: 1 addition & 2 deletions GitHubActionsTestLogger/TestRunStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ internal record TestRunStatistics(
long FailedTestCount,
long SkippedTestCount,
long TotalTestCount,
TimeSpan ElapsedDuration
)
TimeSpan ElapsedDuration)
{
public TestOutcome OverallOutcome
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public ContentionTolerantWriteFileStream(string filePath, FileMode fileMode)
// Backoff and retry if the file is locked
private FileStream CreateInnerStream()
{
for (var retry = 0;; retry++)
for (var retriesRemaining = 10;; retriesRemaining--)
{
try
{
return new FileStream(_filePath, _fileMode);
}
catch (IOException) when (retry < 10)
catch (IOException) when (retriesRemaining > 0)
{
// Variance in delay to avoid overlapping back-offs
Thread.Sleep(RandomEx.Shared.Next(200, 1000));
Expand Down
8 changes: 6 additions & 2 deletions GitHubActionsTestLogger/Utils/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace GitHubActionsTestLogger.Utils.Extensions;

internal static class StringExtensions
{
public static string SubstringUntil(this string str, string sub,
public static string SubstringUntil(
this string str,
string sub,
StringComparison comparison = StringComparison.Ordinal)
{
var index = str.IndexOf(sub, comparison);
Expand All @@ -15,7 +17,9 @@ public static string SubstringUntil(this string str, string sub,
: str[..index];
}

public static string SubstringAfterLast(this string str, string sub,
public static string SubstringAfterLast(
this string str,
string sub,
StringComparison comparison = StringComparison.Ordinal)
{
var index = str.LastIndexOf(sub, comparison);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ internal static class TimeSpanExtensions
{ TotalSeconds: <= 1 } => timeSpan.Milliseconds + "ms",
{ TotalMinutes: <= 1 } => timeSpan.Seconds + "s",
{ TotalHours: <= 1 } => timeSpan.Minutes + "m" + timeSpan.Seconds + "s",
_ => timeSpan.Hours + "h " + timeSpan.Minutes + "m"
_ => timeSpan.Hours + "h" + timeSpan.Minutes + "m"
};
}
2 changes: 1 addition & 1 deletion GitHubActionsTestLogger/Utils/StackFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using GitHubActionsTestLogger.Utils.Extensions;

namespace GitHubActionsTestLogger.Utils;
// Adapted from https://github.com/atifaziz/StackTraceParser

// Adapted from https://github.com/atifaziz/StackTraceParser
internal partial class StackFrame
{
public string MethodCall { get; }
Expand Down

0 comments on commit ae0b645

Please sign in to comment.