-
Notifications
You must be signed in to change notification settings - Fork 29
Description
From LibTest/io/File/openRead_A02_t01.dart:
_main(Directory sandbox) async {
File file = getTempFileSync(parent: sandbox);
file.writeAsBytesSync([1, 2, 3]);
asyncStart();
await file.openRead().listen((data) {
Expect.throws(() {file.deleteSync();});
}).onDone(() {
asyncEnd();
});
}
Please notice that openRead().listen(...)
returns a StreamSubscription
object. The entire openRead().listen(...).onDone()
expression returns void
according to the documention.
There is therefore no point in await ...
ing this expression.
Instead one could use a Completer:
_main(Directory sandbox) async {
File file = getTempFileSync(parent: sandbox);
file.writeAsBytesSync([1, 2, 3]);
asyncStart();
final c = new Completer();
file.openRead().listen((data) {
Expect.throws(() {file.deleteSync();});
}).onDone(() {
c.complete();
asyncEnd();
});
return c.future;
}
Though now the question comes up what this test is actually testing. The Expect.throws(() {file.deleteSync();});
statement expects that the file cannot be deleted while we are getting data. This is not the case on most platforms. For one, the data we get might be the last, so we might have already gotten the EOF (end-of-file). Furthermore on platforms like linux one can easily open a file, someone deletes the file, and we can continue reading from it (this works until the last file open file descriptor is droped, then the file is actually deleted).