@@ -170,29 +170,6 @@ void main() {
170170 expect (uncaughtErrors, isEmpty);
171171 });
172172
173- test ('failed loads are removed from the pending cache and can be retried' , () async {
174- final cache = Cache ();
175- final firstLoad = Completer <ByteData >();
176- final Future <ByteData > pending = cache.putIfAbsent ('icon' , () => firstLoad.future);
177-
178- expect (
179- identical (pending, cache.putIfAbsent ('icon' , () => throw StateError ('duplicate load' ))),
180- isTrue,
181- );
182-
183- final Future <void > expectedFailure = expectLater (pending, throwsStateError);
184- firstLoad.completeError (StateError ('temporarily unavailable' ));
185- await expectedFailure;
186-
187- final recovered = ByteData (2 );
188- final ByteData result = await cache.putIfAbsent (
189- 'icon' ,
190- () => Future <ByteData >.value (recovered),
191- );
192- expect (identical (result, recovered), isTrue);
193- expect (cache.count, 1 );
194- });
195-
196173 test ('clear prevents pending loads from repopulating stale entries' , () async {
197174 final cache = Cache ();
198175 final oldLoad = Completer <ByteData >();
@@ -238,16 +215,20 @@ void main() {
238215 expect (cache.count, 0 );
239216 });
240217
241- test ('eviction remains safe if a new load returns the same Future ' , () async {
218+ test ('an evicted request cannot cache a Future reused by a later request ' , () async {
242219 final cache = Cache ();
243220 final shared = Completer <ByteData >();
244221 final Future <ByteData > first = cache.putIfAbsent ('icon' , () => shared.future);
245222 expect (cache.evict ('icon' ), isTrue);
223+
224+ final Future <int > countBetweenCallbacks = shared.future.then ((_) => cache.count);
246225 final Future <ByteData > second = cache.putIfAbsent ('icon' , () => shared.future);
247226
248- shared.complete (ByteData (1 ));
249- await first;
250- await second;
227+ final data = ByteData (1 );
228+ shared.complete (data);
229+ expect (await first, same (data));
230+ expect (await countBetweenCallbacks, 0 );
231+ expect (await second, same (data));
251232 expect (cache.count, 1 );
252233 });
253234
0 commit comments