Skip to content

Commit e023e70

Browse files
test(audience-sdk): centralise Retry-After HTTP header name
HttpTransportTests had "Retry-After" inline three times (across the delta-seconds, http-date, and past-date 429 tests) and ConsentSyncTests had it once in CapturingHandler.SendAsync. The string is the RFC 7231 standard header name; the SDK reads it via the typed response.Headers.RetryAfter accessor, but the mocks set it by name. Adds a file-local RetryAfterHeader const at the top of each fixture (matching the existing publishable-key / response-body file-local const pattern) and migrates all four sites. Per the user's "everything random goes in a constant" stance. Follow-up to SDK-272 (centralisation of duplicated literals).
1 parent 9f50312 commit e023e70

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/Packages/Audience/Tests/Runtime/ConsentSyncTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ namespace Immutable.Audience.Tests
1212
[TestFixture]
1313
internal class ConsentSyncTests
1414
{
15+
// Standard HTTP header name (RFC 7231) the mock CapturingHandler sets
16+
// on 429 responses to override the SDK's default backoff.
17+
private const string RetryAfterHeader = "Retry-After";
18+
1519
private string _testDir;
1620

1721
[SetUp]
@@ -223,7 +227,7 @@ protected override async Task<HttpResponseMessage> SendAsync(
223227
var response = new HttpResponseMessage(status);
224228
if ((int)status == 429 && RetryAfterSeconds.HasValue)
225229
{
226-
response.Headers.Add("Retry-After", RetryAfterSeconds.Value.ToString());
230+
response.Headers.Add(RetryAfterHeader, RetryAfterSeconds.Value.ToString());
227231
}
228232
return response;
229233
}

src/Packages/Audience/Tests/Runtime/Transport/HttpTransportTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ internal class HttpTransportTests
2020
// Non-test-prefix publishable key. Must not carry pk_imapik-test- (asserts production BaseUrl).
2121
private const string ProdPublishableKey = "pk_imapik-prodkey";
2222

23+
// Standard HTTP header (RFC 7231) the server sets to override the SDK's 429 backoff.
24+
private const string RetryAfterHeader = "Retry-After";
25+
2326
// Response body fixtures.
2427
private const string MalformedResponseBody = "not-json";
2528
private const string EmptyJsonObjectBody = "{}";
@@ -241,7 +244,7 @@ public async Task SendBatchAsync_429_RetryAfterDeltaSeconds_OverridesExpoBackoff
241244
var handler = new MockHandler(() =>
242245
{
243246
var resp = new HttpResponseMessage((HttpStatusCode)429);
244-
resp.Headers.Add("Retry-After", "12");
247+
resp.Headers.Add(RetryAfterHeader, "12");
245248
return resp;
246249
});
247250
using var transport = new HttpTransport(_store, TestDefaults.PublishableKey,
@@ -264,7 +267,7 @@ public async Task SendBatchAsync_429_RetryAfterHttpDate_OverridesExpoBackoff()
264267
var handler = new MockHandler(() =>
265268
{
266269
var resp = new HttpResponseMessage((HttpStatusCode)429);
267-
resp.Headers.Add("Retry-After", DateTimeOffset.UtcNow.AddSeconds(20).ToString("R"));
270+
resp.Headers.Add(RetryAfterHeader, DateTimeOffset.UtcNow.AddSeconds(20).ToString("R"));
268271
return resp;
269272
});
270273
using var transport = new HttpTransport(_store, TestDefaults.PublishableKey,
@@ -286,7 +289,7 @@ public async Task SendBatchAsync_429_PastRetryAfterDate_FallsBackToExpoBackoff()
286289
var handler = new MockHandler(() =>
287290
{
288291
var resp = new HttpResponseMessage((HttpStatusCode)429);
289-
resp.Headers.Add("Retry-After", DateTimeOffset.UtcNow.AddSeconds(-30).ToString("R"));
292+
resp.Headers.Add(RetryAfterHeader, DateTimeOffset.UtcNow.AddSeconds(-30).ToString("R"));
290293
return resp;
291294
});
292295
using var transport = new HttpTransport(_store, TestDefaults.PublishableKey,

0 commit comments

Comments
 (0)