From aa37a931e10f49da9bdb79fa31b938580211eab4 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 6 May 2026 03:48:57 +0000 Subject: [PATCH] test(okhttp): widen SurgeDns stale-refresh TTL to defeat double-expiry race The 1ms positiveTtlMs let the second refreshed entry expire again between the post-refresh assertion and the cache-hit lookup that followed, triggering an extra background refresh that broke the calls=2 invariant on slow CI runners. 100ms TTL with sleep(150) keeps the expiry boundary clearly outside the assertion window. --- .../vitorpamplona/amethyst/service/okhttp/SurgeDnsTest.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/amethyst/src/test/java/com/vitorpamplona/amethyst/service/okhttp/SurgeDnsTest.kt b/amethyst/src/test/java/com/vitorpamplona/amethyst/service/okhttp/SurgeDnsTest.kt index ff7ad1fd6..92384ab57 100644 --- a/amethyst/src/test/java/com/vitorpamplona/amethyst/service/okhttp/SurgeDnsTest.kt +++ b/amethyst/src/test/java/com/vitorpamplona/amethyst/service/okhttp/SurgeDnsTest.kt @@ -141,16 +141,19 @@ class SurgeDnsTest { responses.get() } val syncRefresh = Executor { it.run() } + // 100ms TTL gives both branches enough headroom on slow CI: Thread.sleep(150) reliably + // expires the first entry, and the post-refresh entry can't expire between the two + // assertions below (microseconds apart on any sane runner). val dns = SurgeDns( delegate = upstream, - positiveTtlMs = 1, + positiveTtlMs = 100, positiveTtlJitterMs = 0, refreshExecutor = syncRefresh, ) assertEquals(listOf(ip("1.2.3.4")), dns.lookup("a.example")) - Thread.sleep(20) + Thread.sleep(150) // Upstream now returns a new IP. The next lookup should still serve the OLD IP // immediately, while the synchronous executor performs the refresh inline.