From 493c453d578054912fd7eca655de71ab437e3ce0 Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Fri, 9 Aug 2024 12:53:15 +0200 Subject: [PATCH] Make ios_deploy_test.dart more robust (#153147) The test should not assume that a stream of bytes delivers them in a certain chunked order (e.g. all bytes of a line are delivered in one chunk and the newline comes in another chunk). Instead it should use a line splitter to obtain individual lines and can match those against expectations. This fragile test is broken after [0] which combines writing a string together with the newline instead of seperately. [0] https://dart-review.googlesource.com/c/sdk/+/378024 --- .../general.shard/ios/ios_deploy_test.dart | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart b/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart index 7ef5f83c16..ace4aff5ee 100644 --- a/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart @@ -137,9 +137,8 @@ void main () { '', 'Log after process stop', ])); - expect(stdin.stream.transform(const Utf8Decoder()), emitsInOrder([ + expect(_decodeLines(stdin.stream), emitsInOrder([ 'thread backtrace all', - '\n', 'process detach', ])); expect(await iosDeployDebugger.launchAndAttach(), isTrue); @@ -234,9 +233,8 @@ void main () { '* thread #1, stop reason = Assertion failed:', ])); - expect(stdin.stream.transform(const Utf8Decoder()), emitsInOrder([ + expect(_decodeLines(stdin.stream), emitsInOrder([ 'thread backtrace all', - '\n', 'process detach', ])); @@ -386,7 +384,7 @@ void main () { final IOSDeployDebugger iosDeployDebugger = IOSDeployDebugger.test( processManager: processManager, ); - expect(stdin.stream.transform(const Utf8Decoder()), emits('process detach')); + expect(_decodeLines(stdin.stream), emits('process detach')); await iosDeployDebugger.launchAndAttach(); await iosDeployDebugger.detach(); }); @@ -412,7 +410,7 @@ void main () { testWithoutContext('stop with backtrace', () async { final StreamController> stdin = StreamController>(); - final Stream stdinStream = stdin.stream.transform(const Utf8Decoder()); + final Stream stdinStream = _decodeLines(stdin.stream); final FakeProcessManager processManager = FakeProcessManager.list([ FakeCommand( command: const [ @@ -432,22 +430,20 @@ void main () { // These two futures will deadlock if await-ed sequentially await Future.wait(>[ iosDeployDebugger.stopAndDumpBacktrace(), - stdinStream.take(5).toList().then( + stdinStream.take(3).toList().then( (List lines) => stdinLines = lines, ), ]); expect(stdinLines, const [ 'thread backtrace all', - '\n', 'process detach', - '\n', 'process signal SIGSTOP', ]); }); testWithoutContext('pause with backtrace', () async { final StreamController> stdin = StreamController>(); - final Stream stdinStream = stdin.stream.transform(const Utf8Decoder()); + final Stream stdinStream = _decodeLines(stdin.stream); const String stdout = ''' (lldb) run success @@ -503,9 +499,8 @@ process continue 'frame #0: 0x0000000102eaee80 dyld`dyld3::MachOFile::read_uleb128(Diagnostics&, unsigned char const*&, unsigned char const*) + 36', ), ); - expect(await stdinStream.take(3).toList(), [ + expect(await stdinStream.take(2).toList(), [ 'thread backtrace all', - '\n', 'process detach', ]); }); @@ -711,3 +706,6 @@ class IOSDeployDebuggerWaitForExit extends IOSDeployDebugger { return status; } } + +Stream _decodeLines(Stream> bytes) + => bytes.transform(const Utf8Decoder()).transform(const LineSplitter());