Repository: flutter
Issue: [tool] Adding an `await` to `DefaultResidentCompiler._recompile` fails test(s) in test/general.shard/devfs_test.dart
Labels: P2,team-tool,triaged-tool

Discovered while working on https://github.com/flutter/flutter/pull/151146. ~~Blocks fixing https://github.com/flutter/flutter/issues/137184~~, easily the top crasher of the flutter tool.

### Repro
1. Checkout master (I used fbd6890fb7bc29097ac7a40034ed60a6513f5194).
2. Open [packages/flutter_tools/lib/src/compile.dart](https://github.com/flutter/flutter/blob/e410b7cd5e01554f899d43c5b2a8ee5baea7e760/packages/flutter_tools/lib/src/compile.dart#L748). Add `await Future.value()` after the `server.stdin.writeln('recompile $mainUri $inputKey');` (the line in the link).
3. Run [this test](https://github.com/flutter/flutter/blob/0fc08abe5b9b092214f30664fbec7f2f6ca9d267/packages/flutter_tools/test/general.shard/devfs_test.dart#L499) using `dart test test/general.shard/devfs_test.dart --name "DevFS actually starts compile before processing bundle"` from the packages/flutter_tools directory.

The test will fail:

```
andrewkolos-macbookpro:flutter_tools andrewkolos$ dart test test/general.shard/devfs_test.dart --name "DevFS actually starts compile before processing bundle"
Building package executable... (1.8s)
Built test:test.
00:01 +0: DevFS actually starts compile before processing bundle                                                                                                                                                                
Expected: a value greater than <3>
  Actual: <2>
   Which: is not a value greater than <3>

#0      fail (package:matcher/src/expect/expect.dart:149:31)
#1      _expect (package:matcher/src/expect/expect.dart:144:3)
#2      expect (package:matcher/src/expect/expect.dart:56:3)
#3      main.<anonymous closure> (file:///Users/andrewkolos/Documents/GitHub/flutter/packages/flutter_tools/test/general.shard/devfs_test.dart:603:5)
<asynchronous suspension>
#4      testUsingContext.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (file:///Users/andrewkolos/Documents/GitHub/flutter/packages/flutter_tools/test/src/context.dart:151:26)
<asynchronous suspension>
#5      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#6      testUsingContext.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (file:///Users/andrewkolos/Documents/GitHub/flutter/packages/flutter_tools/test/src/context.dart:140:22)
<asynchronous suspension>

line1
line2
line1
line2

00:01 +0 -1: DevFS actually starts compile before processing bundle [E]                                                                                                                                                         
  Expected: a value greater than <3>
    Actual: <2>
     Which: is not a value greater than <3>
  
  package:matcher                                     expect
  test/general.shard/devfs_test.dart 603:5            main.<fn>
  ===== asynchronous gap ===========================
  test/src/context.dart 151:26                        testUsingContext.<fn>.<fn>.<fn>.<fn>.<fn>
  ===== asynchronous gap ===========================
  package:flutter_tools/src/base/context.dart 153:19  AppContext.run.<fn>
  ===== asynchronous gap ===========================
  test/src/context.dart 140:22                        testUsingContext.<fn>.<fn>.<fn>.<fn>
  

To run this test again: /Users/andrewkolos/Documents/GitHub/flutter/bin/cache/dart-sdk/bin/dart test test/general.shard/devfs_test.dart -p vm --plain-name 'DevFS actually starts compile before processing bundle'
00:01 +0 -1: Some tests failed.                                                                                                                                                                                                 

Consider enabling the flag chain-stack-traces to receive more detailed exceptions.
For example, 'dart test --chain-stack-traces'.
```

Looks like this method deferring to the event loop causes a mis-sequencing of events somehow.