Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,9 @@ Fixed handling of No Content responses
- Updated to latest spec
- Fixed serialization so that nullable fields are not required in deserialization,
and not emitted during serialization if they are null.

## 3.2.1

### Changed

- Fixed retry timeout handling to use the configured timeout value correctly
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var shipengine = new ShipEngine("___YOUR_API_KEY_HERE__");
This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:

- API version: 1.1.202603171403
- SDK version: 3.1.0
- SDK version: 3.2.1
- Generator version: 7.7.0
- Build package: org.openapitools.codegen.languages.CSharpClientCodegen
For more information, please visit [https://www.shipengine.com/contact/](https://www.shipengine.com/contact/)
Expand Down
56 changes: 56 additions & 0 deletions ShipEngineSDK.Test/NetworkTimeoutsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,61 @@ public async Task RetryAfterIsGreaterThanTimeoutSetting()
Assert.Equal(ErrorCode.Timeout, ex.ErrorCode);
Assert.Equal("204c855f-dcc0-4270-ba12-c585fc5ef4bf", ex.RequestId);
}

// Regression: TimeSpan.Seconds returns only the seconds component (0-59),
// so a timeout of 60+ seconds would incorrectly compare as 0 and always
// throw a timeout exception instead of retrying.
[Fact]
public async Task RetryWorksWithTimeoutGreaterThanOrEqualTo60Seconds()
{
var config = new Config(apiKey: "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk", timeout: TimeSpan.FromSeconds(60), retries: 1);
var mockShipEngineFixture = new MockShipEngineFixture(config);

mockShipEngineFixture.MockHandler.Protected()
.SetupSequence<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.Is<HttpRequestMessage>(m =>
m.Method == HttpMethod.Put &&
m.RequestUri.AbsolutePath == "/v1/labels/se-1234/void"),
ItExpr.IsAny<CancellationToken>())
.Returns(Task.FromResult(RateLimitResponseMessage))
.Returns(Task.FromResult(
new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(VoidLabelResponse)
}
));

// Should retry successfully, not throw a timeout exception
await mockShipEngineFixture.ShipEngine.VoidLabelWithLabelId("se-1234");

mockShipEngineFixture.AssertRequest(HttpMethod.Put, "/v1/labels/se-1234/void", numberOfCalls: 2);
}

[Fact]
public async Task TimeoutMessageShowsCorrectMillisecondsForLargeTimeouts()
{
// RetryAfter header is 1 second; set timeout to 0.5s so it triggers the timeout path
var config = new Config(apiKey: "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk", timeout: TimeSpan.FromMilliseconds(1500), retries: 1);
var mockShipEngineFixture = new MockShipEngineFixture(config);

var rateLimitWithHighRetryAfter = new HttpResponseMessage((HttpStatusCode)429);
rateLimitWithHighRetryAfter.Content = new StringContent(rateLimitResponse);
rateLimitWithHighRetryAfter.Headers.Add("RetryAfter", "2");

mockShipEngineFixture.MockHandler.Protected()
.SetupSequence<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.Is<HttpRequestMessage>(m =>
m.Method == HttpMethod.Put &&
m.RequestUri.AbsolutePath == "/v1/labels/se-1234/void"),
ItExpr.IsAny<CancellationToken>())
.Returns(Task.FromResult(rateLimitWithHighRetryAfter));

var ex = await Assert.ThrowsAsync<ShipEngineException>(async () => await mockShipEngineFixture.ShipEngine.VoidLabelWithLabelId("se-1234"));

Assert.Equal("The request took longer than the 1500 milliseconds allowed", ex.Message);
Assert.Equal(ErrorCode.Timeout, ex.ErrorCode);
}
}
}
4 changes: 2 additions & 2 deletions ShipEngineSDK/ShipEngineClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ private async Task WaitAndRetry(HttpResponseMessage? response, Config config, Sh
retryAfter = 5;
}

if (config.Timeout.Seconds < retryAfter)
if (config.Timeout.TotalSeconds < retryAfter)
{
throw new ShipEngineException(
$"The request took longer than the {config.Timeout.Milliseconds} milliseconds allowed",
$"The request took longer than the {config.Timeout.TotalMilliseconds} milliseconds allowed",
ErrorSource.Shipengine,
ErrorType.System,
ErrorCode.Timeout,
Expand Down
2 changes: 1 addition & 1 deletion ShipEngineSDK/ShipEngineSDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PackageId>ShipEngine</PackageId>
<PackageTags>sdk;rest;api;shipping;rates;label;tracking;cost;address;validation;normalization;fedex;ups;usps;</PackageTags>

<Version>3.2.0</Version>
<Version>3.2.1</Version>
<Authors>ShipEngine</Authors>
<Company>ShipEngine</Company>
<Summary>The official ShipEngine C# SDK for .NET</Summary>
Expand Down
2 changes: 1 addition & 1 deletion openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ignoreFileOverride": "./.openapi-generator-ignore",
"library": "generichost",
"additionalProperties": {
"packageVersion": "3.2.0",
"packageVersion": "3.2.1",
"targetFramework": "netstandard2.0",
"validatable": false,
"sourceFolder": "",
Expand Down
Loading