OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library future_test; | 5 library future_test; |
6 | 6 |
7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 | 10 |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 Expect.isTrue(index == 0 || index == 2, "$index"); | 872 Expect.isTrue(index == 0 || index == 2, "$index"); |
873 Expect.isFalse(uncaughts[index]); | 873 Expect.isFalse(uncaughts[index]); |
874 uncaughts[index] = true; | 874 uncaughts[index] = true; |
875 asyncEnd(); | 875 asyncEnd(); |
876 }); | 876 }); |
877 } | 877 } |
878 | 878 |
879 void testWaitSyncError() { | 879 void testWaitSyncError() { |
880 var cms = const Duration(milliseconds: 100); | 880 var cms = const Duration(milliseconds: 100); |
881 var cleanups = new List.filled(3, false); | 881 var cleanups = new List.filled(3, false); |
882 var uncaughts = new List.filled(3, false); | |
883 asyncStart(); | 882 asyncStart(); |
884 asyncStart(); | 883 asyncStart(); |
885 runZoned(() { | 884 runZoned(() { |
886 Future.wait(new Iterable.generate(5, (i) { | 885 Future.wait(new Iterable.generate(5, (i) { |
887 if (i != 3) return new Future.delayed(cms * (i + 1), () => i); | 886 if (i != 3) return new Future.delayed(cms * (i + 1), () => i); |
888 throw "throwing synchronously in iterable"; | 887 throw "throwing synchronously in iterable"; |
889 }), cleanUp: (index) { | 888 }), cleanUp: (index) { |
890 Expect.isFalse(cleanups[index]); | 889 Expect.isFalse(cleanups[index]); |
891 cleanups[index] = true; | 890 cleanups[index] = true; |
892 if (cleanups.every((x) => x)) asyncEnd(); | 891 if (cleanups.every((x) => x)) asyncEnd(); |
893 }); | 892 }); |
894 }, onError: (e, s) { | 893 }, onError: (e, s) { |
895 asyncEnd(); | 894 asyncEnd(); |
896 }); | 895 }); |
897 } | 896 } |
898 | 897 |
898 void testWaitSyncError2() { | |
899 asyncStart(); | |
900 Future.wait([null]).catchError((e, st) { | |
901 // Makes sure that the `catchError` is invoked. | |
902 // Regression test: an earlier version of `Future.wait` would propagate | |
903 // the error too soon for the code to install an error handler. | |
904 // `testWaitSyncError` didn't show this problem, because the `runZoned` | |
905 // was already installed. | |
906 asyncEnd(); | |
907 }); | |
908 } | |
909 | |
910 void testWaitSyncError3() { | |
Lasse Reichstein Nielsen
2016/09/06 09:53:27
Add comment saying what you are testing: That zone
floitsch
2016/09/06 09:57:15
Done.
| |
911 var caughtError; | |
912 var count = 0; | |
913 | |
914 AsyncError errorCallback( | |
915 Zone self, ZoneDelegate parent, Zone zone, Object error, | |
916 StackTrace stackTrace) { | |
917 Expect.equals(0, count); | |
918 count++; | |
919 caughtError = error; | |
920 return parent.errorCallback(zone, error, stackTrace); | |
921 } | |
922 | |
923 asyncStart(); | |
924 runZoned(() { | |
925 Future.wait([null]).catchError((e, st) { | |
926 Expect.isNotNull(caughtError); | |
Lasse Reichstein Nielsen
2016/09/06 09:53:27
Check that caughtError is identical to e.
floitsch
2016/09/06 09:57:16
Done.
| |
927 asyncEnd(); | |
928 }); | |
929 }, zoneSpecification: new ZoneSpecification(errorCallback: errorCallback)); | |
930 } | |
931 | |
899 void testBadFuture() { | 932 void testBadFuture() { |
900 var bad = new BadFuture(); | 933 var bad = new BadFuture(); |
901 // Completing with bad future (then call throws) puts error in result. | 934 // Completing with bad future (then call throws) puts error in result. |
902 asyncStart(); | 935 asyncStart(); |
903 Completer completer = new Completer(); | 936 Completer completer = new Completer(); |
904 completer.complete(bad); | 937 completer.complete(bad); |
905 completer.future.then((_) { Expect.fail("unreachable"); }, | 938 completer.future.then((_) { Expect.fail("unreachable"); }, |
906 onError: (e, s) { | 939 onError: (e, s) { |
907 Expect.isTrue(completer.isCompleted); | 940 Expect.isTrue(completer.isCompleted); |
908 asyncEnd(); | 941 asyncEnd(); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1089 | 1122 |
1090 testChainedFutureValue(); | 1123 testChainedFutureValue(); |
1091 testChainedFutureValueDelay(); | 1124 testChainedFutureValueDelay(); |
1092 testChainedFutureError(); | 1125 testChainedFutureError(); |
1093 | 1126 |
1094 testSyncFuture_i13368(); | 1127 testSyncFuture_i13368(); |
1095 | 1128 |
1096 testWaitCleanUp(); | 1129 testWaitCleanUp(); |
1097 testWaitCleanUpError(); | 1130 testWaitCleanUpError(); |
1098 testWaitSyncError(); | 1131 testWaitSyncError(); |
1132 testWaitSyncError2(); | |
1133 testWaitSyncError3(); | |
1099 | 1134 |
1100 testBadFuture(); | 1135 testBadFuture(); |
1101 | 1136 |
1102 testTypes(); | 1137 testTypes(); |
1103 | 1138 |
1104 testAnyValue(); | 1139 testAnyValue(); |
1105 testAnyError(); | 1140 testAnyError(); |
1106 testAnyIgnoreIncomplete(); | 1141 testAnyIgnoreIncomplete(); |
1107 testAnyIgnoreError(); | 1142 testAnyIgnoreError(); |
1108 | 1143 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1160 Future whenComplete(action()) { | 1195 Future whenComplete(action()) { |
1161 return new Future.microtask(action).then((_) => this); | 1196 return new Future.microtask(action).then((_) => this); |
1162 } | 1197 } |
1163 Stream asStream() { | 1198 Stream asStream() { |
1164 return (new StreamController()..add(_result)..close()).stream; | 1199 return (new StreamController()..add(_result)..close()).stream; |
1165 } | 1200 } |
1166 Future timeout(Duration duration, {onTimeout()}) { | 1201 Future timeout(Duration duration, {onTimeout()}) { |
1167 return this; | 1202 return this; |
1168 } | 1203 } |
1169 } | 1204 } |
OLD | NEW |