Skip to content

Commit f5c8639

Browse files
committed
fix asyncEval integration test failures
1 parent 686699f commit f5c8639

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

packages/devtools_app/test/shared/eval_integration_test.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,18 @@ void main() {
115115
serviceManager: serviceConnection.serviceManager,
116116
);
117117

118-
final instance = await eval
119-
.asyncEval(
120-
'await Future.error(StateError("foo"), StackTrace.current)',
121-
isAlive: isAlive,
122-
)
123-
.then<FutureFailedException>(
124-
(_) => throw Exception(
125-
'The FutureFailedException was not thrown as expected.',
126-
),
127-
onError: (Object? err) => err,
128-
);
118+
late final FutureFailedException instance;
119+
try {
120+
await eval.asyncEval(
121+
'await Future.error(StateError("foo"), StackTrace.current)',
122+
isAlive: isAlive,
123+
);
124+
throw Exception(
125+
'The FutureFailedException was not thrown as expected.',
126+
);
127+
} on FutureFailedException catch (e) {
128+
instance = e;
129+
}
129130

130131
expect(
131132
instance.expression,

packages/devtools_app_shared/lib/src/service/eval_on_dart_library.dart

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,21 @@ class EvalOnDartLibrary extends DisposableController
345345

346346
static int _nextAsyncEvalId = 0;
347347

348+
Future<InstanceRef> _safeEvalWithRetry(
349+
EvalOnDartLibrary eval,
350+
String expression, {
351+
required Disposable? isAlive,
352+
Map<String, String>? scope,
353+
}) async {
354+
try {
355+
return await eval.safeEval(expression, isAlive: isAlive, scope: scope);
356+
} catch (_) {
357+
// In some environments, bootstrap evals can race isolate readiness.
358+
await Future<void>.delayed(const Duration(milliseconds: 50));
359+
return await eval.safeEval(expression, isAlive: isAlive, scope: scope);
360+
}
361+
}
362+
348363
EvalOnDartLibrary? _dartDeveloperEvalCache;
349364
EvalOnDartLibrary get _dartDeveloperEval {
350365
return _dartDeveloperEvalCache ??= EvalOnDartLibrary(
@@ -395,11 +410,13 @@ class EvalOnDartLibrary extends DisposableController
395410
final readerGroup = 'asyncEval-$futureId';
396411

397412
/// Workaround to not being able to import libraries directly from an evaluation
398-
final postEventRef = await _dartDeveloperEval.safeEval(
413+
final postEventRef = await _safeEvalWithRetry(
414+
_dartDeveloperEval,
399415
'postEvent',
400416
isAlive: isAlive,
401417
);
402-
final widgetInspectorServiceRef = await _widgetInspectorEval.safeEval(
418+
final widgetInspectorServiceRef = await _safeEvalWithRetry(
419+
_widgetInspectorEval,
403420
'WidgetInspectorService.instance',
404421
isAlive: isAlive,
405422
);
@@ -438,7 +455,7 @@ class EvalOnDartLibrary extends DisposableController
438455

439456
final resultRef = await evalInstance(
440457
'() {'
441-
' final result = widgetInspectorService.toObject("$readerId", "$readerGroup") as List;'
458+
' final result = widgetInspectorService.toObject("$readerId", "$readerGroup");'
442459
' widgetInspectorService.disposeGroup("$readerGroup");'
443460
' return result;'
444461
'}()',

0 commit comments

Comments
 (0)