Skip to content

Commit 710a756

Browse files
test(audience-sdk): backoff assertions derive from Constants.HttpBackoff*Ms
HttpTransportTests pinned the backoff schedule with literal millisecond numbers (5_000 / 10_000 / 20_000 / 40_000 / 60_000). Constants.HttpBackoff*Ms now own those values, but the tests still hardcoded the numbers, so a change to the constants would have flipped production behaviour while the tests kept passing against the old expectations. Switch every BackoffMs / NextAttemptAt assertion to derive from Constants.HttpBackoff{1st,2nd,3rd,4th,Cap}Ms. Follow-up to SDK-272 (centralisation of duplicated literals).
1 parent 6f7f276 commit 710a756

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public async Task SendBatchAsync_429_NoRetryAfter_KeepsFilesAndUsesExpoBackoff_N
217217

218218
Assert.AreEqual(1, _store.Count(), "429 must keep files for retry");
219219
Assert.IsTrue(transport.IsInBackoffWindow);
220-
Assert.AreEqual(5_000, transport.BackoffMs);
220+
Assert.AreEqual(Constants.HttpBackoff1stMs, transport.BackoffMs);
221221
Assert.IsNull(reportedError, "429 is transient; must not fire onError");
222222
}
223223

@@ -282,7 +282,7 @@ public async Task SendBatchAsync_429_PastRetryAfterDate_FallsBackToExpoBackoff()
282282

283283
await transport.SendBatchAsync();
284284

285-
Assert.AreEqual(5_000, transport.BackoffMs);
285+
Assert.AreEqual(Constants.HttpBackoff1stMs, transport.BackoffMs);
286286
Assert.IsTrue(transport.IsInBackoffWindow);
287287
}
288288

@@ -306,7 +306,7 @@ public async Task SendBatchAsync_429ThenSuccess_DeliversBatchAndClearsBackoff()
306306

307307
await transport.SendBatchAsync();
308308
Assert.AreEqual(1, _store.Count(), "429 keeps the batch");
309-
Assert.AreEqual(5_000, transport.BackoffMs);
309+
Assert.AreEqual(Constants.HttpBackoff1stMs, transport.BackoffMs);
310310

311311
Advance(5_001);
312312
await transport.SendBatchAsync();
@@ -384,7 +384,7 @@ public async Task SendBatchAsync_5xx_KeepsFilesAndIncreasesBackoff()
384384

385385
Assert.AreEqual(1, _store.Count(), "5xx should keep files for retry");
386386
Assert.IsTrue(transport.IsInBackoffWindow);
387-
Assert.AreEqual(5000, transport.BackoffMs, "first failure = 5s backoff");
387+
Assert.AreEqual(Constants.HttpBackoff1stMs, transport.BackoffMs, "first failure = HttpBackoff1stMs");
388388
Assert.IsNotNull(reportedError);
389389
Assert.AreEqual(AudienceErrorCode.FlushFailed, reportedError!.Code);
390390
}
@@ -400,27 +400,27 @@ public async Task BackoffMs_EscalatesOnlyAfterWindowElapsed()
400400
// Schedule: 5s → 10s → 20s → 40s → 60s cap.
401401
// Each escalation requires the previous window to have elapsed.
402402
await transport.SendBatchAsync();
403-
Assert.AreEqual(5_000, transport.BackoffMs);
403+
Assert.AreEqual(Constants.HttpBackoff1stMs, transport.BackoffMs);
404404

405405
Advance(5_001);
406406
await transport.SendBatchAsync();
407-
Assert.AreEqual(10_000, transport.BackoffMs);
407+
Assert.AreEqual(Constants.HttpBackoff2ndMs, transport.BackoffMs);
408408

409409
Advance(10_001);
410410
await transport.SendBatchAsync();
411-
Assert.AreEqual(20_000, transport.BackoffMs);
411+
Assert.AreEqual(Constants.HttpBackoff3rdMs, transport.BackoffMs);
412412

413413
Advance(20_001);
414414
await transport.SendBatchAsync();
415-
Assert.AreEqual(40_000, transport.BackoffMs);
415+
Assert.AreEqual(Constants.HttpBackoff4thMs, transport.BackoffMs);
416416

417417
Advance(40_001);
418418
await transport.SendBatchAsync();
419-
Assert.AreEqual(60_000, transport.BackoffMs, "reaches 60s cap after 40s step");
419+
Assert.AreEqual(Constants.HttpBackoffCapMs, transport.BackoffMs, "reaches cap after 4th step");
420420

421421
Advance(60_001);
422422
await transport.SendBatchAsync();
423-
Assert.AreEqual(60_000, transport.BackoffMs, "stays at cap");
423+
Assert.AreEqual(Constants.HttpBackoffCapMs, transport.BackoffMs, "stays at cap");
424424
}
425425

426426
[Test]
@@ -432,7 +432,7 @@ public async Task BackoffMs_DoesNotEscalateWhileInsidePreviousWindow()
432432
handler: handler, getUtcNow: _getUtcNow);
433433

434434
await transport.SendBatchAsync();
435-
Assert.AreEqual(5_000, transport.BackoffMs);
435+
Assert.AreEqual(Constants.HttpBackoff1stMs, transport.BackoffMs);
436436
var firstDeadline = transport.NextAttemptAt;
437437
Assert.IsNotNull(firstDeadline);
438438

@@ -447,12 +447,12 @@ public async Task BackoffMs_DoesNotEscalateWhileInsidePreviousWindow()
447447
// Another premature retry: still no escalation.
448448
Advance(3_000);
449449
await transport.SendBatchAsync();
450-
Assert.AreEqual(5_000, transport.BackoffMs);
450+
Assert.AreEqual(Constants.HttpBackoff1stMs, transport.BackoffMs);
451451

452452
// Wait out the window, fail again → now we escalate.
453453
_utcNow = firstDeadline.Value.AddMilliseconds(1);
454454
await transport.SendBatchAsync();
455-
Assert.AreEqual(10_000, transport.BackoffMs);
455+
Assert.AreEqual(Constants.HttpBackoff2ndMs, transport.BackoffMs);
456456
}
457457

458458
[Test]
@@ -474,11 +474,11 @@ public async Task BackoffMs_ResetsAfterSuccess()
474474
handler: handler, getUtcNow: _getUtcNow);
475475

476476
await transport.SendBatchAsync();
477-
Assert.AreEqual(5_000, transport.BackoffMs);
477+
Assert.AreEqual(Constants.HttpBackoff1stMs, transport.BackoffMs);
478478

479479
Advance(5_001);
480480
await transport.SendBatchAsync();
481-
Assert.AreEqual(10_000, transport.BackoffMs);
481+
Assert.AreEqual(Constants.HttpBackoff2ndMs, transport.BackoffMs);
482482

483483
Advance(10_001);
484484
await transport.SendBatchAsync();
@@ -580,7 +580,7 @@ public async Task IsInBackoffWindow_ClearsAfterNextAttemptAtElapses()
580580
await transport.SendBatchAsync();
581581

582582
Assert.IsTrue(transport.IsInBackoffWindow, "within window immediately after failure");
583-
Assert.AreEqual(now.AddMilliseconds(5_000), transport.NextAttemptAt);
583+
Assert.AreEqual(now.AddMilliseconds(Constants.HttpBackoff1stMs), transport.NextAttemptAt);
584584

585585
// Advance the clock just before NextAttemptAt: still backing off.
586586
now = now.AddMilliseconds(4_999);

0 commit comments

Comments
 (0)