ci: faster, stricter CI (instrumented gate, parallel jobs, test forks) (#1348)
This commit is contained in:
6 files changed
+58
-19
No files matched your search
@@ -415,6 +415,7 @@ object HermesWsClient {
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun probeLivenessOnTransportChange(
|
||||
timeoutMs: Long = LIVENESS_PROBE_TIMEOUT_MS,
|
||||
onFailureAction: () -> Unit = {
|
||||
synchronized(outboundLock) {
|
||||
if (connected.get()) webSocket?.cancel()
|
||||
@@ -426,7 +427,7 @@ object HermesWsClient {
|
||||
transportProbeJob =
|
||||
wsScope.launch {
|
||||
Log.d(TAG, "Network transport changed — probing WebSocket liveness")
|
||||
val alive = runCatching { ping(LIVENESS_PROBE_TIMEOUT_MS) }.isSuccess
|
||||
val alive = runCatching { ping(timeoutMs) }.isSuccess
|
||||
if (alive) {
|
||||
Log.d(TAG, "WebSocket liveness probe succeeded on new transport")
|
||||
return@launch
|
||||
|
||||
@@ -25,6 +25,9 @@ open class NotificationReplyReceiver : BroadcastReceiver() {
|
||||
const val EXTRA_SESSION_ID = "extra_session_id"
|
||||
private const val REPLY_TIMEOUT_MS = 5_000L
|
||||
|
||||
/** Overall deadline for persisting and submitting one notification reply. */
|
||||
private const val PERSISTENCE_TIMEOUT_MS = 5_000L
|
||||
|
||||
/**
|
||||
* Turn-boundary read budget inside the reply deadline. Deliberately tight:
|
||||
* the probe sits on the reply path, so a slow or unreachable gateway must
|
||||
@@ -44,6 +47,9 @@ open class NotificationReplyReceiver : BroadcastReceiver() {
|
||||
*/
|
||||
internal open fun goAsyncCompat(): BroadcastReceiver.PendingResult = goAsync()
|
||||
|
||||
/** Overridable so tests can prove the timeout path without waiting 5s. */
|
||||
internal open val persistenceTimeoutMs: Long get() = PERSISTENCE_TIMEOUT_MS
|
||||
|
||||
/**
|
||||
* Test-friendly wrapper for notification creation. Override in tests to
|
||||
* avoid [NotificationCompat.Builder.build()] calling Android framework
|
||||
@@ -75,7 +81,7 @@ open class NotificationReplyReceiver : BroadcastReceiver() {
|
||||
val pendingResult = goAsyncCompat()
|
||||
replyScope.launch {
|
||||
try {
|
||||
withTimeout(5000L) {
|
||||
withTimeout(persistenceTimeoutMs) {
|
||||
withContext(Dispatchers.IO) {
|
||||
val db =
|
||||
com.m57.hermescontrol.data.local.HermesDatabase
|
||||
|
||||
@@ -2188,12 +2188,13 @@ class HermesWsClientTest {
|
||||
|
||||
val failureLatch = CountDownLatch(1)
|
||||
HermesWsClient.probeLivenessOnTransportChange(
|
||||
timeoutMs = 50L,
|
||||
onFailureAction = {
|
||||
failureLatch.countDown()
|
||||
},
|
||||
)
|
||||
|
||||
assertTrue("Expected failure action to be invoked on failed ping", failureLatch.await(6, TimeUnit.SECONDS))
|
||||
assertTrue("Expected failure action to be invoked on failed ping", failureLatch.await(3, TimeUnit.SECONDS))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+12
-5
@@ -412,16 +412,23 @@ class NotificationReplyReceiverTest {
|
||||
kotlinx.coroutines.delay(10000)
|
||||
}
|
||||
|
||||
receiver.onReceive(mockContext, mockIntent)
|
||||
// Same timeout path as production, with a short deadline instead of 5s.
|
||||
val shortTimeoutReceiver =
|
||||
object : NotificationReplyReceiver() {
|
||||
override fun goAsyncCompat(): BroadcastReceiver.PendingResult = mockPendingResult
|
||||
|
||||
// Wait longer than the 5-second timeout, but less than the 10-second delay
|
||||
Thread.sleep(6000)
|
||||
override fun buildReplyNotification(context: Context): Notification = mockNotification
|
||||
|
||||
override val persistenceTimeoutMs: Long = 50L
|
||||
}
|
||||
|
||||
shortTimeoutReceiver.onReceive(mockContext, mockIntent)
|
||||
|
||||
// Timeout should be caught in catch block and logged
|
||||
verify { android.util.Log.e("NotificationReply", any<String>(), any()) }
|
||||
verify(timeout = 3_000) { android.util.Log.e("NotificationReply", any<String>(), any()) }
|
||||
|
||||
// Pending result must still finish after timeout
|
||||
verify { mockPendingResult.finish() }
|
||||
verify(timeout = 3_000) { mockPendingResult.finish() }
|
||||
}
|
||||
|
||||
// ── Helpers ────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in new issue
Block a user