@@ -483,10 +483,12 @@ void main() {
483
483
late MockVmService service;
484
484
late StreamController <Event > allEvents;
485
485
late Future <void > allIsolatesExited;
486
+ Object ? lastError;
486
487
487
488
late List <String > received;
488
489
Future <void > Function (String )? delayTheOnPauseCallback;
489
490
late bool stopped;
491
+ late Set <String > resumeFailures;
490
492
491
493
void startEvent (String id, String groupId, [String ? name]) =>
492
494
allEvents.add (event (
@@ -516,34 +518,48 @@ void main() {
516
518
}
517
519
518
520
setUp (() {
519
- (service, allEvents) = createServiceAndEventStreams ();
520
-
521
- // Backfill was tested above, so this test does everything using events,
522
- // for simplicity. No need to report any isolates.
523
- when (service.getVM ()).thenAnswer ((_) async => VM ());
524
-
525
- received = < String > [];
526
- delayTheOnPauseCallback = null ;
527
- when (service.resume (any)).thenAnswer ((invocation) async {
528
- final id = invocation.positionalArguments[0 ];
529
- received.add ('Resume $id ' );
530
- return Success ();
531
- });
532
-
533
- stopped = false ;
534
- allIsolatesExited = IsolatePausedListener (
535
- service,
536
- (iso, isLastIsolateInGroup) async {
537
- expect (stopped, isFalse);
538
- received.add ('Pause ${iso .id }. Collect group ${iso .isolateGroupId }? '
539
- '${isLastIsolateInGroup ? 'Yes' : 'No' }' );
540
- if (delayTheOnPauseCallback != null ) {
541
- await delayTheOnPauseCallback !(iso.id! );
542
- received.add ('Pause done ${iso .id }' );
521
+ Zone .current.fork (
522
+ specification: ZoneSpecification (
523
+ handleUncaughtError: (Zone self, ZoneDelegate parent, Zone zone,
524
+ Object error, StackTrace stackTrace) {
525
+ lastError = error;
526
+ },
527
+ ),
528
+ ).runGuarded (() {
529
+ (service, allEvents) = createServiceAndEventStreams ();
530
+
531
+ // Backfill was tested above, so this test does everything using events,
532
+ // for simplicity. No need to report any isolates.
533
+ when (service.getVM ()).thenAnswer ((_) async => VM ());
534
+
535
+ received = < String > [];
536
+ delayTheOnPauseCallback = null ;
537
+ resumeFailures = < String > {};
538
+ when (service.resume (any)).thenAnswer ((invocation) async {
539
+ final id = invocation.positionalArguments[0 ];
540
+ received.add ('Resume $id ' );
541
+ if (resumeFailures.contains (id)) {
542
+ throw RPCError ('resume' , - 32000 , id);
543
543
}
544
- },
545
- (message) => received.add (message),
546
- ).waitUntilAllExited ();
544
+ return Success ();
545
+ });
546
+
547
+ stopped = false ;
548
+ allIsolatesExited = IsolatePausedListener (
549
+ service,
550
+ (iso, isLastIsolateInGroup) async {
551
+ expect (stopped, isFalse);
552
+ received
553
+ .add ('Pause ${iso .id }. Collect group ${iso .isolateGroupId }? '
554
+ '${isLastIsolateInGroup ? 'Yes' : 'No' }' );
555
+ if (delayTheOnPauseCallback != null ) {
556
+ await delayTheOnPauseCallback !(iso.id! );
557
+ received.add ('Pause done ${iso .id }' );
558
+ }
559
+ },
560
+ (message) => received.add (message),
561
+ ).waitUntilAllExited ();
562
+ });
547
563
});
548
564
549
565
test ('ordinary flows' , () async {
@@ -889,5 +905,40 @@ void main() {
889
905
// Don't try to resume B, because the VM service is already shut down.
890
906
]);
891
907
});
908
+
909
+ test ('throw when resuming main isolate is ignored' , () async {
910
+ resumeFailures = {'main' };
911
+
912
+ startEvent ('main' , '1' );
913
+ startEvent ('other' , '2' );
914
+ pauseEvent ('other' , '2' );
915
+ exitEvent ('other' , '2' );
916
+ pauseEvent ('main' , '1' );
917
+ exitEvent ('main' , '1' );
918
+
919
+ await endTest ();
920
+ expect (lastError, isNull);
921
+
922
+ expect (received, [
923
+ 'Pause other. Collect group 2? Yes' ,
924
+ 'Resume other' ,
925
+ 'Pause main. Collect group 1? Yes' ,
926
+ 'Resume main' ,
927
+ ]);
928
+ });
929
+
930
+ test ('throw when resuming other isolate is not ignored' , () async {
931
+ resumeFailures = {'other' };
932
+
933
+ startEvent ('main' , '1' );
934
+ startEvent ('other' , '2' );
935
+ pauseEvent ('other' , '2' );
936
+ exitEvent ('other' , '2' );
937
+ pauseEvent ('main' , '1' );
938
+ exitEvent ('main' , '1' );
939
+
940
+ await endTest ();
941
+ expect (lastError, isA <RPCError >());
942
+ });
892
943
});
893
944
}
0 commit comments