test: de-poison unit suite — drop static Dispatchers mocks, kill leaked WS timers (#833)

Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
M57andM57 authored and GitHub committed 2026-08-07 04:18:14 +03:00
1 parent fe79ff42b4
commit 4645a2b6e7
8 files changed
+51 -33

No files matched your search

@@ -3,10 +3,8 @@ package com.m57.hermescontrol.ui.common
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.m57.hermescontrol.data.remote.NetworkResult
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
interface ToastHost {
fun clearToast()
@@ -22,7 +20,11 @@ inline fun <T> ViewModel.safeLaunchLoad(
if (currentJob?.isActive == true) return currentJob
onStart()
return viewModelScope.launch {
val result = withContext(Dispatchers.IO) { apiCall() }
// No withContext(Dispatchers.IO) hop: Retrofit suspend calls already
// run off the caller thread, and an explicit hop forces every
// consuming test to fake Dispatchers.IO with a static mock — the
// JVM-wide bleed that flakes the suite (see the de-poisoned tests).
val result = apiCall()
when (result) {
is NetworkResult.Success -> onSuccess(result.data)
is NetworkResult.Failure -> onError(result.error.message)