OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:fake_async/fake_async.dart'; | 7 import 'package:fake_async/fake_async.dart'; |
8 import 'package:pool/pool.dart'; | 8 import 'package:pool/pool.dart'; |
9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 expect(blockedResourceAllocated, isFalse); | 89 expect(blockedResourceAllocated, isFalse); |
90 completer.complete(); | 90 completer.complete(); |
91 return new Future.delayed(new Duration(microseconds: 1)); | 91 return new Future.delayed(new Duration(microseconds: 1)); |
92 }).then((_) { | 92 }).then((_) { |
93 expect(blockedResourceAllocated, isTrue); | 93 expect(blockedResourceAllocated, isTrue); |
94 }); | 94 }); |
95 | 95 |
96 async.elapse(new Duration(seconds: 1)); | 96 async.elapse(new Duration(seconds: 1)); |
97 }); | 97 }); |
98 }); | 98 }); |
| 99 |
| 100 // Regression test for #3. |
| 101 test("can be called immediately before close()", () async { |
| 102 var pool = new Pool(1); |
| 103 pool.withResource(expectAsync(() {})); |
| 104 await pool.close(); |
| 105 }); |
99 }); | 106 }); |
100 | 107 |
101 group("with a timeout", () { | 108 group("with a timeout", () { |
102 test("doesn't time out if there are no pending requests", () { | 109 test("doesn't time out if there are no pending requests", () { |
103 new FakeAsync().run((async) { | 110 new FakeAsync().run((async) { |
104 var pool = new Pool(50, timeout: new Duration(seconds: 5)); | 111 var pool = new Pool(50, timeout: new Duration(seconds: 5)); |
105 for (var i = 0; i < 50; i++) { | 112 for (var i = 0; i < 50; i++) { |
106 expect(pool.request(), completes); | 113 expect(pool.request(), completes); |
107 } | 114 } |
108 | 115 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 }); | 276 }); |
270 | 277 |
271 pool.request(); | 278 pool.request(); |
272 }); | 279 }); |
273 }); | 280 }); |
274 | 281 |
275 group("close()", () { | 282 group("close()", () { |
276 test("disallows request() and withResource()", () { | 283 test("disallows request() and withResource()", () { |
277 var pool = new Pool(1)..close(); | 284 var pool = new Pool(1)..close(); |
278 expect(pool.request, throwsStateError); | 285 expect(pool.request, throwsStateError); |
279 expect(pool.withResource(() {}), throwsStateError); | 286 expect(() => pool.withResource(() {}), throwsStateError); |
280 }); | 287 }); |
281 | 288 |
282 test("pending requests are fulfilled", () async { | 289 test("pending requests are fulfilled", () async { |
283 var pool = new Pool(1); | 290 var pool = new Pool(1); |
284 var resource1 = await pool.request(); | 291 var resource1 = await pool.request(); |
285 expect(pool.request().then((resource2) { | 292 expect(pool.request().then((resource2) { |
286 resource2.release(); | 293 resource2.release(); |
287 }), completes); | 294 }), completes); |
288 expect(pool.close(), completes); | 295 expect(pool.close(), completes); |
289 resource1.release(); | 296 resource1.release(); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 /// | 426 /// |
420 /// This should only be called within a [FakeAsync.run] zone. | 427 /// This should only be called within a [FakeAsync.run] zone. |
421 Matcher get doesNotComplete => predicate((future) { | 428 Matcher get doesNotComplete => predicate((future) { |
422 expect(future, new isInstanceOf<Future>()); | 429 expect(future, new isInstanceOf<Future>()); |
423 | 430 |
424 var stack = new Trace.current(1); | 431 var stack = new Trace.current(1); |
425 future.then((_) => registerException( | 432 future.then((_) => registerException( |
426 new TestFailure("Expected future not to complete."), stack)); | 433 new TestFailure("Expected future not to complete."), stack)); |
427 return true; | 434 return true; |
428 }); | 435 }); |
OLD | NEW |