Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting a test specific timeout through test.json. #81

Merged
merged 4 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ a `test.json` file. An example of this file:
"versionSpecific": false,
"type": "xunit",
"cleanup": true,
"timeoutMultiplier": 1.0,
"ignoredRIDs": [
"fedora",
"fedora.29",
Expand Down Expand Up @@ -169,6 +170,21 @@ trait `blue` is set, or both `os=fedora` and `arch=x64` are set.
]
```

- `timeoutMultiplier`

This is a number, that scales the default timeout for a specific test.
The default timeout can be set through the command-line `--timeout`
argument.

Example:

A test with the following `timeoutMultiplier` will be allowed to twice
tmds marked this conversation as resolved.
Show resolved Hide resolved
as long.

```
"timeoutMultiplier": 2.0
```
tmds marked this conversation as resolved.
Show resolved Hide resolved

## Notes on Writing Tests

Some notes for writing tests:
Expand Down
8 changes: 4 additions & 4 deletions Turkey/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public static async Task<int> Run(string testRoot,
IEnumerable<string> trait,
int timeout)
{
TimeSpan timeoutForEachTest;
TimeSpan defaultTimeout;
if (timeout == 0)
{
timeoutForEachTest = new TimeSpan(hours: 0, minutes: 5, seconds: 0);
defaultTimeout = new TimeSpan(hours: 0, minutes: 5, seconds: 0);
}
else
{
timeoutForEachTest = new TimeSpan(hours: 0, minutes: 0, seconds: timeout);
defaultTimeout = new TimeSpan(hours: 0, minutes: 0, seconds: timeout);
}

var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
Expand Down Expand Up @@ -129,7 +129,7 @@ public static async Task<int> Run(string testRoot,
verboseOutput: verbose,
nuGetConfig: nuGetConfig);

var results = await runner.ScanAndRunAsync(testOutputs, logDir.FullName, timeoutForEachTest);
var results = await runner.ScanAndRunAsync(testOutputs, logDir.FullName, defaultTimeout);

int exitCode = (results.Failed == 0) ? 0 : 1;
return exitCode;
Expand Down
1 change: 1 addition & 0 deletions Turkey/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TestDescriptor
public bool VersionSpecific { get; set; }
public string Type { get; set; }
public bool Cleanup { get; set; }
public double TimeoutMultiplier { get; set; } = 1.0;
public List<string> IgnoredRIDs { get; set; } = new();
public List<string> SkipWhen { get; set; } = new();
}
Expand Down
8 changes: 5 additions & 3 deletions Turkey/TestOutputFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public async override Task AfterParsingTestAsync(string name, bool enabled)

public async override Task AfterRunningTestAsync(string name, TestResult result, StringBuilder testLog, TimeSpan testTime)
{
string elapsedTime = testTime.TotalMilliseconds.ToString();
int minutes = (int)testTime.TotalMinutes;
string elapsedTime = minutes == 0 ? $"{testTime.Seconds}s"
: $"{minutes}m {testTime.Seconds}s";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also included this (unrelated) change which makes it easier to read the elapsed time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of tests now show (0s). Do you think printing the time in milliseconds might be useful for those tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add additional code to round that up to 1s, but the millisecond precision isn't useful imo.

string resultOutput = null;
if (Console.IsOutputRedirected || Console.IsErrorRedirected)
{
Expand All @@ -31,7 +33,7 @@ public async override Task AfterRunningTestAsync(string name, TestResult result,
case TestResult.Failed: resultOutput = "FAIL"; break;
case TestResult.Skipped: resultOutput = "SKIP"; break;
}
Console.WriteLine($"[{resultOutput}]\t({elapsedTime}ms)");
Console.WriteLine($"[{resultOutput}]\t({elapsedTime})");
}
else
{
Expand All @@ -41,7 +43,7 @@ public async override Task AfterRunningTestAsync(string name, TestResult result,
case TestResult.Failed: resultOutput = "\u001b[31mFAIL\u001b[0m"; break;
case TestResult.Skipped: resultOutput = "SKIP"; break;
}
Console.WriteLine($"[{resultOutput}]\t({elapsedTime}ms)");
Console.WriteLine($"[{resultOutput}]\t({elapsedTime})");
}
}

Expand Down
5 changes: 3 additions & 2 deletions Turkey/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public TestRunner(SystemUnderTest system, DirectoryInfo root, bool verboseOutput
this.nuGetConfig = nuGetConfig;
}

public async Task<TestResults> ScanAndRunAsync(List<TestOutput> outputs, string logDir, TimeSpan timeoutForEachTest)
public async Task<TestResults> ScanAndRunAsync(List<TestOutput> outputs, string logDir, TimeSpan defaultTimeout)
{
await outputs.ForEachAsync(output => output.AtStartupAsync());

Expand Down Expand Up @@ -105,7 +105,8 @@ public async Task<TestResults> ScanAndRunAsync(List<TestOutput> outputs, string

await outputs.ForEachAsync(output => output.AfterParsingTestAsync(testName, !test.Skip));

using var cts = timeoutForEachTest == TimeSpan.Zero ? null : new CancellationTokenSource(timeoutForEachTest);
TimeSpan testTimeout = test.Descriptor.TimeoutMultiplier * defaultTimeout;
using var cts = testTimeout == TimeSpan.Zero ? null : new CancellationTokenSource(testTimeout);
var cancellationToken = cts is null ? default : cts.Token;
Action<string> testLogger = null;

Expand Down
Loading