fix(#284): remove legacy WS callbacks (CODE-04), migrate tests to StateFlow/SharedFlow (#303)

- Remove onMessage/onConnected/onDisconnected/onError callback
  properties from HermesWsClient — redundant with events SharedFlow
  and connectionStatus StateFlow
- Rewrite all 10 tests to use connectionStatus.first{} and
  events.first{} instead of callback + CountDownLatch patterns
- Remove polling loop for RECONNECTING status — flow inherently
  waits for the right value

Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
M57andM57 authored and GitHub committed 2026-06-22 14:05:01 +03:00
1 parent 15a4748634
commit 2acfaabfcb
2 files changed
+29 -96

No files matched your search

@@ -93,13 +93,6 @@ object HermesWsClient {
/** Observable connection status: DISCONNECTED / CONNECTING / CONNECTED / RECONNECTING */
val connectionStatus: StateFlow<ConnectionStatus> = _connectionStatus.asStateFlow()
// ── Callbacks (legacy / convenience) ─────────────────────────────────
var onMessage: ((WsEvent) -> Unit)? = null
var onConnected: (() -> Unit)? = null
var onDisconnected: ((reason: String?) -> Unit)? = null
var onError: ((Throwable) -> Unit)? = null
// ── Connection helpers ────────────────────────────────────────────────
val isConnected: Boolean get() = connected.get()
@@ -216,7 +209,6 @@ object HermesWsClient {
private fun emit(event: WsEvent) {
_events.tryEmit(event)
onMessage?.invoke(event)
}
// ── Listener ─────────────────────────────────────────────────────────
@@ -230,7 +222,6 @@ object HermesWsClient {
connected.set(true)
_connectionStatus.value = ConnectionStatus.CONNECTED
currentBackoff = INITIAL_BACKOFF_MS
onConnected?.invoke()
}
override fun onMessage(
@@ -267,7 +258,6 @@ object HermesWsClient {
) {
Log.i(TAG, "WebSocket closed: $code $reason")
connected.set(false)
onDisconnected?.invoke(reason)
_connectionStatus.value = ConnectionStatus.RECONNECTING
scheduleReconnect()
}
@@ -279,8 +269,6 @@ object HermesWsClient {
) {
Log.e(TAG, "WebSocket failure: ${t.message}", t)
connected.set(false)
onError?.invoke(t)
onDisconnected?.invoke(t.message)
_connectionStatus.value = ConnectionStatus.RECONNECTING
scheduleReconnect()
}