Skip to content

Commit

Permalink
Fix tests, add retry mechanism for server delete (intermittent failur…
Browse files Browse the repository at this point in the history
…es due to deadlocks)
  • Loading branch information
Ryan Criddle committed Dec 14, 2022
1 parent 03c8622 commit e027fd6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
dotnet build --configuration release src/
test:
docker:
- image: mcr.microsoft.com/dotnet/core/sdk:3.1
- image: mcr.microsoft.com/dotnet/sdk:6.0
steps:
- checkout
- run:
Expand Down
15 changes: 10 additions & 5 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
{
"version": "0.1.0",
"version": "2.0.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"label": "build",
"type": "shell",
"command": "dotnet",
"args": [
"build",
"${workspaceRoot}/src/Postmark.Tests/Postmark.Tests.csproj"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
"problemMatcher": "$msCompile",
"group": {
"_id": "build",
"isDefault": false
}
}
]
}
2 changes: 1 addition & 1 deletion src/Postmark.Tests/ClientBounceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ClientBounceTests : ClientBaseFixture
{
public ClientBounceTests()
{
Client = new PostmarkClient(WriteTestServerToken, BaseUrl);
Client = new PostmarkClient(ReadSeleniumTestServerToken, BaseUrl);
}

[Fact]
Expand Down
4 changes: 1 addition & 3 deletions src/Postmark.Tests/Postmark.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ApplicationIcon/>
<TargetFramework>net6.0</TargetFramework>
<OutputTypeEx>library</OutputTypeEx>
<StartupObject/>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4"/>
Expand Down
18 changes: 17 additions & 1 deletion src/Postmark/PostmarkAdminClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,23 @@ public async Task<PostmarkServer> GetServerAsync(int serverId)
/// <returns></returns>
public async Task<PostmarkResponse> DeleteServerAsync(int serverId)
{
return await this.ProcessNoBodyRequestAsync<PostmarkResponse>("/servers/" + serverId, verb: HttpMethod.Delete);
// Adding a retry mechanism because server deletion currently fails intermittently due to deadlocks.
// This is a temporary fix, and should be removed once the server delete operation is more reliable.
var attemptsRemain = 5;
while (true)
{
try
{
return await this.ProcessNoBodyRequestAsync<PostmarkResponse>("/servers/" + serverId, verb: HttpMethod.Delete);
}
catch
{
if (--attemptsRemain == 0)
{
throw;
}
}
}
}

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions src/Postmark/PostmarkClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ protected async Task<TResponse> ProcessRequestAsync<TRequestBody, TResponse>(
/// <param name="parameters"></param>
/// <param name="verb">The http verb to use for the request.</param>
/// <returns></returns>
protected async Task<TResponse> ProcessNoBodyRequestAsync<TResponse>
(string apiPath, IDictionary<string, object> parameters = null, HttpMethod verb = null)
protected async Task<TResponse> ProcessNoBodyRequestAsync<TResponse>(
string apiPath,
IDictionary<string, object> parameters = null,
HttpMethod verb = null)
{
parameters = parameters ?? new Dictionary<string, object>();

Expand Down

0 comments on commit e027fd6

Please sign in to comment.