Skip to content

Faulty LibTest/io/File/openRead_A02_t01.dart test #206

@mkustermann

Description

@mkustermann

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).

@dcharkes

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions