diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 017f3a4f..eca1ab7c 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -551,6 +551,10 @@ class MeshCoreConnector extends ChangeNotifier { bool get isAutoReconnectScheduled => (_shouldAutoReconnect || _shouldAutoReconnectTcp) && (_reconnectTimer?.isActive ?? false); + + @visibleForTesting + int get reconnectAttemptsForTesting => _reconnectAttempts; + String? get activeTcpEndpoint => _tcpConnector.activeEndpoint; bool get isTcpTransportConnected => _state == MeshCoreConnectionState.connected && diff --git a/test/connector/tcp_auto_reconnect_test.dart b/test/connector/tcp_auto_reconnect_test.dart index 9d63ab17..be4c1555 100644 --- a/test/connector/tcp_auto_reconnect_test.dart +++ b/test/connector/tcp_auto_reconnect_test.dart @@ -208,14 +208,13 @@ void main() { _connector.state == MeshCoreConnectionState.disconnected && _connector.isAutoReconnectScheduled, ); - await _waitFor( - () => !_connector.isAutoReconnectScheduled, - pollInterval: const Duration(milliseconds: 1), - ); - // The timer firing proves an attempt started; wait for its failure to - // finish and the next backoff to become active. + final firstScheduledAttempt = _connector.reconnectAttemptsForTesting; + // Wait for the failed attempt to schedule its next backoff. The timer's + // inactive window can be shorter than a test poll interval, so observe + // the monotonic retry count instead of trying to catch that window. await _waitFor( () => + _connector.reconnectAttemptsForTesting > firstScheduledAttempt && _connector.state == MeshCoreConnectionState.disconnected && _connector.isAutoReconnectScheduled, );