import 'package:flutter_test/flutter_test.dart'; import 'package:pluriwave/servicios/servicio_audio.dart'; /// Test-isolation seam for [PluriWaveAudioHandler]. /// /// A handler nobody releases keeps running after the test that built it: its /// terminal-state floor timer, its `ControladorReconexion` backoff (1/2/4/8/16 /// s, longer than most of the tests that arm it) and anything still queued on /// its source-change chain. When one of those finally performs a source change /// it calls `_crearPlayer()`, which reads the CURRENT /// [PluriWaveAudioHandler.fabricaReproductorPrueba] — so a dead handler builds /// a double bound to a LATER test's script and drives it, incrementing that /// test's counters for work it never asked for. /// /// That is why `servicio_audio_transporte_test.dart` behaved differently run /// alone and run inside the whole suite. A suite that passes under those /// conditions passes by luck, and luck runs out on a broken build exactly when /// it matters. /// /// Usage — call ONCE at the top of `main()` and build every handler through /// the returned function: /// /// ```dart /// final crearHandler = registrarHandlersLiberables(); /// ... /// final handler = crearHandler(); /// ``` /// /// The `tearDown` it registers covers every group in the file. PluriWaveAudioHandler Function() registrarHandlersLiberables() { final creados = []; tearDown(() async { // Released in reverse creation order so a handler built on top of an // earlier one is torn down first. `liberar` is idempotent, so a test that // already released its own handler is fine. for (final handler in creados.reversed) { await handler.liberar(); } creados.clear(); }); return () { final handler = PluriWaveAudioHandler(); creados.add(handler); return handler; }; }