diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 077b3b077..6f2cc3cd0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -268,8 +268,9 @@ jobs: - uses: actions/checkout@v3 - uses: subosito/flutter-action@v2 with: - flutter-version: ${{ inputs.flutter_version }} - channel: 'stable' + # TODO: use `inputs.flutter_version` and change to `stable`, when flutter/flutter#129534 has been released. + flutter-version: '3.13.0-0.1.pre' + channel: 'beta' - uses: bluefireteam/melos-action@main - name: Install Flutter requirements for Linux run: | diff --git a/packages/audioplayers/example/integration_test/lib_test.dart b/packages/audioplayers/example/integration_test/lib_test.dart index 0a06a794e..11743db8b 100644 --- a/packages/audioplayers/example/integration_test/lib_test.dart +++ b/packages/audioplayers/example/integration_test/lib_test.dart @@ -19,10 +19,6 @@ void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); final isAndroid = !kIsWeb && Platform.isAndroid; - final isLinux = !kIsWeb && Platform.isLinux; - - // FIXME(gustl22): Cannot reuse event channel with same id on Linux (flutter/flutter#126209) - var linuxPlayerCount = 0; final wavUrl1TestData = LibSourceTestData( source: UrlSource(wavUrl1), @@ -78,10 +74,7 @@ void main() { // Start all players simultaneously final iterator = List.generate(audioTestDataList.length, (i) => i); - if (isLinux) { - // FIXME(gustl22): Linux needs additional pump (#1507) - await tester.pump(); - } + await tester.pumpLinux(); await Future.wait( iterator.map((i) => players[i].play(audioTestDataList[i].source)), ); @@ -97,11 +90,9 @@ void main() { expect(position, greaterThan(Duration.zero)); } await players[i].stop(); + await tester.pumpLinux(); } - if (!isLinux) { - // FIXME(gustl22): Linux not disposing properly (#1507) - await Future.wait(players.map((p) => p.dispose())); - } + await Future.wait(players.map((p) => p.dispose())); }, // FIXME: Causes media error on Android (see #1333, #1353) // Unexpected platform error: MediaPlayer error with @@ -115,10 +106,7 @@ void main() { for (var i = 0; i < audioTestDataList.length; i++) { final td = audioTestDataList[i]; - if (isLinux) { - // FIXME(gustl22): Linux needs additional pump (#1507) - await tester.pump(); - } + await tester.pumpLinux(); await player.play(td.source); await tester.pumpAndSettle(); // Sources take some time to get initialized @@ -131,10 +119,8 @@ void main() { } await player.stop(); } - if (!isLinux) { - // FIXME(gustl22): Linux not disposing properly (#1507) - await player.dispose(); - } + await tester.pumpLinux(); + await player.dispose(); }); }); @@ -160,10 +146,7 @@ void main() { await AudioPlayer.global.setAudioContext(audioContext); await player.setAudioContext(audioContext); - if (isLinux) { - // FIXME(gustl22): Linux needs additional pump (#1507) - await tester.pump(); - } + await tester.pumpLinux(); await player.play(td.source); await tester.pumpAndSettle(); await tester.pump(td.duration + const Duration(seconds: 8)); @@ -181,10 +164,8 @@ void main() { await tester.pumpAndSettle(); await tester.pump(td.duration + const Duration(seconds: 8)); expect(player.state, PlayerState.completed); - if (!isLinux) { - // FIXME(gustl22): Linux not disposing properly (#1507) - await player.dispose(); - } + await tester.pumpLinux(); + await player.dispose(); }, skip: !features.hasForceSpeaker, ); @@ -211,10 +192,7 @@ void main() { await AudioPlayer.global.setAudioContext(audioContext); await player.setAudioContext(audioContext); - if (isLinux) { - // FIXME(gustl22): Linux needs additional pump (#1507) - await tester.pump(); - } + await tester.pumpLinux(); await player.setSource(td.source); await player.resume(); await tester.pumpAndSettle(); @@ -237,10 +215,8 @@ void main() { expect(player.state, PlayerState.playing); await player.stop(); expect(player.state, PlayerState.stopped); - if (!isLinux) { - // FIXME(gustl22): Linux not disposing properly (#1507) - await player.dispose(); - } + await tester.pumpLinux(); + await player.dispose(); }, skip: !features.hasForceSpeaker || !features.hasLowLatency, ); @@ -250,7 +226,7 @@ void main() { testWidgets('Emit platform log', (tester) async { final logCompleter = Completer(); - final playerId = 'somePlayerId${isLinux ? linuxPlayerCount++ : ''}'; + const playerId = 'somePlayerId'; final player = AudioPlayer(playerId: playerId); final onLogSub = player.onLog.listen( logCompleter.complete, @@ -264,6 +240,7 @@ void main() { final log = await logCompleter.future; expect(log, 'SomeLog'); await onLogSub.cancel(); + await tester.pumpLinux(); await player.dispose(); }); @@ -289,21 +266,16 @@ void main() { (tester) async { final player = AudioPlayer(); try { + await tester.pumpLinux(); // Throws PlatformException via MethodChannel: - if (isLinux) { - // FIXME(gustl22): Linux needs additional pump (#1507) - await tester.pump(); - } await player.setSource(AssetSource(invalidAsset)); fail('PlatformException not thrown'); // ignore: avoid_catches_without_on_clauses } catch (e) { expect(e, isInstanceOf()); } - if (!isLinux) { - // FIXME(gustl22): Linux not disposing properly (#1507) - await player.dispose(); - } + await tester.pumpLinux(); + await player.dispose(); }, ); @@ -312,21 +284,16 @@ void main() { (tester) async { final player = AudioPlayer(); try { + await tester.pumpLinux(); // Throws PlatformException via MethodChannel: - if (isLinux) { - // FIXME(gustl22): Linux needs additional pump (#1507) - await tester.pump(); - } await player.setSource(UrlSource('non_existent.txt')); fail('PlatformException not thrown'); // ignore: avoid_catches_without_on_clauses } catch (e) { expect(e, isInstanceOf()); } - if (!isLinux) { - // FIXME(gustl22): Linux not disposing properly (#1507) - await player.dispose(); - } + await tester.pumpLinux(); + await player.dispose(); }, ); }); @@ -335,7 +302,7 @@ void main() { testWidgets('#create and #dispose', (tester) async { final platform = AudioplayersPlatformInterface.instance; - final playerId = 'somePlayerId${isLinux ? linuxPlayerCount++ : ''}'; + const playerId = 'somePlayerId'; await platform.create(playerId); await tester.pumpAndSettle(); await platform.dispose(playerId); @@ -356,7 +323,7 @@ void main() { testWidgets('#setSource #getPosition and #getDuration', (tester) async { final platform = AudioplayersPlatformInterface.instance; - final playerId = 'somePlayerId${isLinux ? linuxPlayerCount++ : ''}'; + const playerId = 'somePlayerId'; await platform.create(playerId); final preparedCompleter = Completer(); @@ -372,10 +339,7 @@ void main() { }, onError: preparedCompleter.completeError, ); - if (isLinux) { - // FIXME(gustl22): Linux needs additional pump (#1507) - await tester.pump(); - } + await tester.pumpLinux(); await platform.setSourceUrl( playerId, (wavUrl1TestData.source as UrlSource).url, @@ -389,16 +353,14 @@ void main() { ); await onPreparedSub.cancel(); - if (!isLinux) { - // FIXME(gustl22): Linux not disposing properly (#1507) - await platform.dispose(playerId); - } + await tester.pumpLinux(); + await platform.dispose(playerId); }); testWidgets('#seek with millisecond precision', (tester) async { final platform = AudioplayersPlatformInterface.instance; - final playerId = 'somePlayerId${isLinux ? linuxPlayerCount++ : ''}'; + const playerId = 'somePlayerId'; await platform.create(playerId); final preparedCompleter = Completer(); @@ -414,10 +376,7 @@ void main() { }, onError: preparedCompleter.completeError, ); - if (isLinux) { - // FIXME(gustl22): Linux needs additional pump (#1507) - await tester.pump(); - } + await tester.pumpLinux(); await platform.setSourceUrl( playerId, (mp3Url1TestData.source as UrlSource).url, @@ -439,16 +398,14 @@ void main() { expect(await platform.getCurrentPosition(playerId), 21); await onPreparedSub.cancel(); - if (!isLinux) { - // FIXME(gustl22): Linux not disposing properly (#1507) - await platform.dispose(playerId); - } + await tester.pumpLinux(); + await platform.dispose(playerId); }); testWidgets('Set same source twice (#1520)', (tester) async { final platform = AudioplayersPlatformInterface.instance; - final playerId = 'somePlayerId${isLinux ? linuxPlayerCount++ : ''}'; + const playerId = 'somePlayerId'; await platform.create(playerId); final eventStream = platform.getEventStream(playerId); @@ -465,10 +422,7 @@ void main() { }, onError: preparedCompleter.completeError, ); - if (isLinux) { - // FIXME(gustl22): Linux needs additional pump (#1507) - await tester.pump(); - } + await tester.pumpLinux(); await platform.setSourceUrl( playerId, (wavUrl1TestData.source as UrlSource).url, @@ -476,10 +430,8 @@ void main() { await preparedCompleter.future.timeout(const Duration(seconds: 30)); await onPreparedSub.cancel(); } - if (!isLinux) { - // FIXME(gustl22): Linux not disposing properly (#1507) - await platform.dispose(playerId); - } + await tester.pumpLinux(); + await platform.dispose(playerId); }); }); @@ -487,7 +439,7 @@ void main() { testWidgets('Listen and cancel twice', (tester) async { final platform = AudioplayersPlatformInterface.instance; - final playerId = 'somePlayerId${isLinux ? linuxPlayerCount++ : ''}'; + const playerId = 'somePlayerId'; await platform.create(playerId); final eventStream = platform.getEventStream(playerId); @@ -495,44 +447,15 @@ void main() { final eventSub = eventStream.listen(null); await eventSub.cancel(); } - if (!isLinux) { - // FIXME(gustl22): Linux not disposing properly (#1507) - await platform.dispose(playerId); - } + await tester.pumpLinux(); + await platform.dispose(playerId); }); - // TODO(gustl22): remove once https://github.com/flutter/flutter/issues/126209 - // is fixed, as tests should cover the problem in flutter engine. - testWidgets( - 'Reuse same platform event channel id', - (tester) async { - final platform = AudioplayersPlatformInterface.instance; - - const playerId = 'somePlayerId'; - await platform.create(playerId); - - final eventStreamSub = platform.getEventStream(playerId).listen((_) {}); - - await eventStreamSub.cancel(); - await platform.dispose(playerId); - - // Recreate player with same player Id - await platform.create(playerId); - - final eventStreamSub2 = - platform.getEventStream(playerId).listen((_) {}); - - await eventStreamSub2.cancel(); - await platform.dispose(playerId); - }, - skip: isLinux, - ); - testWidgets('Emit platform error', (tester) async { final errorCompleter = Completer(); final platform = AudioplayersPlatformInterface.instance; - final playerId = 'somePlayerId${isLinux ? linuxPlayerCount++ : ''}'; + const playerId = 'somePlayerId'; await platform.create(playerId); final eventStreamSub = platform @@ -551,6 +474,7 @@ void main() { expect(platformException.code, 'SomeErrorCode'); expect(platformException.message, 'SomeErrorMessage'); await eventStreamSub.cancel(); + await tester.pumpLinux(); await platform.dispose(playerId); }); @@ -578,3 +502,12 @@ void main() { }); }); } + +extension on WidgetTester { + Future pumpLinux() async { + if (!kIsWeb && Platform.isLinux) { + // FIXME(gustl22): Linux needs additional pump (#1556) + await pump(); + } + } +}