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

Add more extensive coverage for Task.Timeout #3388

Merged
merged 5 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/templates/common.lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#@ actionDockerLayerCaching = "jpribyl/action-docker-layer-caching@c632825d12ec837065f49726ea27ddd40bcc7894" #! 0.1.1
#@ actionDockerBuild = "docker/build-push-action@6e95f19fb8c9e00a1a391941edbc0ae30c1799f7" #! 2.7.0
#@ actionDockerRun = "addnab/docker-run-action@3e77f186b7a929ef010f183a9e24c0f9955ea609" #! v3
#@ actionCoveralls = "coverallsapp/github-action@ca2a9dd5a20b12fa9aa428e0a6418a60a38bab22" #! v2.1.1
#@ actionCoveralls = "coverallsapp/github-action@95b1a2355bd0e526ad2fd62da9fd386ad4c98474" #! v2.2.1
#@ actionDeleteArtifact = "geekyeggo/delete-artifact@dc8092f14c4245ef6a3501b1669b171c12899167" #! v1
#@ actionGithubRelease = "ncipollo/release-action@3ac4132803a6419fa2a7f4e9dbd1d93fceb690b9" #! v1.8.8
#@ actionDownloadAllArtifacts = "dawidd6/action-download-artifact@46b4ae883bf0726f5949d025d31cb62c7a5ac70c" #! v2.14.1
Expand Down
1 change: 1 addition & 0 deletions .github/templates/test-code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: ./report.lcov
git-commit: ${{ github.event.pull_request.head.sha }}
compare-sha: ${{ github.event.pull_request.base.sha }}
- name: Output Coveralls response
run: echo ${{ steps.publish-coveralls.outputs.coveralls-api-result }}
- #@ publishTestsResults("TestResults.Linux.xml", "Code Coverage")
3 changes: 2 additions & 1 deletion .github/workflows/test-code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,12 @@ jobs:
run: ./tools/coverlet ${{ steps.dotnet-publish.outputs.executable-path }} -t ${{ steps.dotnet-publish.outputs.executable-path }}/Realm.Tests -a '--result=TestResults.Linux.xml --labels=After --baasurl=${{ inputs.realmUrl }} --baascluster=${{ inputs.clusterName }} --baasapikey=${{ secrets.AtlasPublicKey}} --baasprivateapikey=${{ secrets.AtlasPrivateKey}} --baasprojectid=${{ secrets.AtlasProjectId }} --baasdifferentiator=code-coverage' -f lcov -o ./report.lcov --exclude '[Realm.Tests]*' --exclude '[Realm.Fody]*' --exclude '[Realm.PlatformHelpers]*'
- name: Publish Coverage
id: publish-coveralls
uses: coverallsapp/github-action@ca2a9dd5a20b12fa9aa428e0a6418a60a38bab22
uses: coverallsapp/github-action@95b1a2355bd0e526ad2fd62da9fd386ad4c98474
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: ./report.lcov
git-commit: ${{ github.event.pull_request.head.sha }}
compare-sha: ${{ github.event.pull_request.base.sha }}
- name: Output Coveralls response
run: echo ${{ steps.publish-coveralls.outputs.coveralls-api-result }}
- name: Publish Unit Test Results
Expand Down
30 changes: 26 additions & 4 deletions Tests/Realm.Tests/Database/APITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,35 @@ public void TestTaskTimeout()
{
TestHelpers.RunAsyncTest(async () =>
{
try
await TestHelpers.AssertThrows<TimeoutException>(() => GetVoidTask().Timeout(10));

var ex = await TestHelpers.AssertThrows<TimeoutException>(() => GetVoidTask().Timeout(10, detail: "some detail"));
Assert.That(ex.Message, Does.Contain("some detail"));

var errorTask = Task.FromException(new ArgumentException("invalid argument"));
var ex2 = await TestHelpers.AssertThrows<ArgumentException>(() => GetVoidTask().Timeout(10, errorTask));
Assert.That(ex2.Message, Does.Contain("invalid argument"));

await TestHelpers.AssertThrows<TimeoutException>(() => GetIntTask().Timeout(10));

var ex3 = await TestHelpers.AssertThrows<TimeoutException>(() => GetIntTask().Timeout(10, detail: "another detail"));
Assert.That(ex3.Message, Does.Contain("another detail"));

var ex4 = await TestHelpers.AssertThrows<ArgumentException>(() => GetFaultedIntTask().Timeout(1000));
Assert.That(ex4.Message, Does.Contain("super invalid"));

static async Task<int> GetIntTask()
{
await Task.Delay(100).Timeout(10);
await Task.Delay(100);
return 5;
}
catch (Exception ex)

static Task GetVoidTask() => Task.Delay(100);

static async Task<int> GetFaultedIntTask()
{
Assert.That(ex, Is.TypeOf<TimeoutException>());
await Task.Delay(1);
throw new ArgumentException("super invalid");
}
});
}
Expand Down
Loading