mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:43:57 +00:00
[web] delete file_sample_api_test - a flaky and obsolete test.
This test has non-deterministic failures (rate 30% on mac, 10% on linux and windows) caused likely by a data-race ([example log][1]). The test has a write to set the contents of a file, and a corresponding read. The error makes it appear as if the read occurred before the write completed. This API is part of the [createWriter][2] proposal, which was abandoned early on (almost a decade ago) and documented as deprecated. As a result I believe this test is providing coverage for obsolete functionality. In fact, the API for the `write` returns void and appears synchronous, but my guess is that it is not. There is no API to ensure the write completes as far as I know. An alternative here would be to use timers to add a significant delay between the operations. It is also worth noting that the [requestFileSystem][3] API to access the FileSystem (used here and in the fileapi tests) is also deprecated and not supported in firefox or safari. Given the flakiness issue and the fact that this API is already deprecated, I'm not really seeing the value in keeping the test. [1]: https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket/8767600632278735009/+/u/test_results/ignored_flaky_test_failure_logs [2]: https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry/createWriter [3]: https://developer.mozilla.org/en-US/docs/Web/API/Window/requestFileSystem Change-Id: I92ad6399218c6a17cfa029a99b99afcfadde0035 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332282 Reviewed-by: Srujan Gaddam <srujzs@google.com> Commit-Queue: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
parent
cbc21d2738
commit
8f4d4391e1
|
@ -1,144 +0,0 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
library file_sample;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:html';
|
||||
|
||||
import 'package:async_helper/async_helper.dart';
|
||||
import 'package:expect/minitest.dart';
|
||||
|
||||
// Expected output from all functions, asynchronous, and event routines.
|
||||
const String log_results = 'test-first\n' +
|
||||
'acquire START\n' +
|
||||
'acquire CALLBACK START\n' +
|
||||
'acquire CALLBACK END\n' +
|
||||
'first START\n' +
|
||||
'first END\n' +
|
||||
'test-second\n' +
|
||||
'second START\n' +
|
||||
'second END\n' +
|
||||
'reader onLoadEnd event\n' +
|
||||
'file content = XYZZY Output\n';
|
||||
|
||||
// Simple logger to record all output.
|
||||
class Logger {
|
||||
StringBuffer _log = new StringBuffer();
|
||||
|
||||
void log(String message) {
|
||||
_log.writeln(message);
|
||||
}
|
||||
|
||||
String get contents => _log.toString();
|
||||
}
|
||||
|
||||
Logger testLog = new Logger();
|
||||
|
||||
Future<FileSystem>? _fileSystem;
|
||||
|
||||
late DirectoryEntry _myDirectory;
|
||||
|
||||
Future<FileSystem> get fileSystem async {
|
||||
if (_fileSystem != null) return _fileSystem!;
|
||||
|
||||
testLog.log('acquire START');
|
||||
_fileSystem = window.requestFileSystem(100);
|
||||
|
||||
var fs = await _fileSystem!;
|
||||
testLog.log('acquire CALLBACK START');
|
||||
expect(fs.runtimeType, FileSystem);
|
||||
expect(fs.root.runtimeType, DirectoryEntry);
|
||||
testLog.log('acquire CALLBACK END');
|
||||
|
||||
return _fileSystem!;
|
||||
}
|
||||
|
||||
Future<FileEntry> createFile() async {
|
||||
var fs = await fileSystem;
|
||||
|
||||
_myDirectory =
|
||||
await fs.root!.createDirectory('my_directory') as DirectoryEntry;
|
||||
|
||||
FileEntry fileEntry = await _myDirectory.createFile('log.txt') as FileEntry;
|
||||
|
||||
expect(fileEntry.isFile, true);
|
||||
expect(fileEntry.name, 'log.txt');
|
||||
expect(fileEntry.fullPath, '/my_directory/log.txt');
|
||||
|
||||
FileWriter writer = await fileEntry.createWriter();
|
||||
|
||||
Blob blob = new Blob(['XYZZY Output'], 'text/plain');
|
||||
|
||||
writer.write(blob);
|
||||
|
||||
var reader = new FileReader();
|
||||
|
||||
var completer = new Completer<String>();
|
||||
|
||||
reader.onLoadEnd.listen((event) {
|
||||
testLog.log('reader onLoadEnd event');
|
||||
dynamic target = event.currentTarget;
|
||||
testLog.log('file content = ${target.result}');
|
||||
expect(target.result, 'XYZZY Output');
|
||||
|
||||
completer.complete(target.result);
|
||||
});
|
||||
|
||||
Blob readBlob = await fileEntry.file();
|
||||
|
||||
reader.readAsText(readBlob);
|
||||
|
||||
// Wait until onLoadEnd if fired.
|
||||
await completer.future;
|
||||
|
||||
return new Future<FileEntry>.value(fileEntry);
|
||||
}
|
||||
|
||||
Future<List<Entry>> readEntries(DirectoryEntry directory) async {
|
||||
DirectoryReader reader = directory.createReader();
|
||||
List<Entry> entries = await reader.readEntries();
|
||||
return entries;
|
||||
}
|
||||
|
||||
Future testFileSystemRequest() async {
|
||||
testLog.log('test-first');
|
||||
var fs = await fileSystem;
|
||||
testLog.log('first START');
|
||||
expect(fs.runtimeType, FileSystem);
|
||||
expect(fs.root.runtimeType, DirectoryEntry);
|
||||
testLog.log('first END');
|
||||
}
|
||||
|
||||
Future testFileSystemRequestCreateRW() async {
|
||||
testLog.log('test-second');
|
||||
var fs = await fileSystem;
|
||||
testLog.log('second START');
|
||||
expect(fs.runtimeType, FileSystem);
|
||||
expect(fs.root.runtimeType, DirectoryEntry);
|
||||
testLog.log('second END');
|
||||
|
||||
FileEntry fileEntry = await createFile();
|
||||
expect(fileEntry.name, 'log.txt');
|
||||
|
||||
List<Entry> entries = await readEntries(fs.root!);
|
||||
expect(entries.length > 0, true);
|
||||
expect(entries[0].isDirectory, true);
|
||||
expect(entries[0].name, 'my_directory');
|
||||
|
||||
List<Entry> myEntries = await readEntries(_myDirectory);
|
||||
expect(myEntries.length, 1);
|
||||
expect(myEntries[0].isFile, true);
|
||||
expect(myEntries[0].name, 'log.txt');
|
||||
|
||||
// Validate every function, async and event mechanism successfully ran.
|
||||
expect(testLog.contents, log_results);
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncTest(() async {
|
||||
await testFileSystemRequest();
|
||||
await testFileSystemRequestCreateRW();
|
||||
});
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
|
||||
// @dart = 2.9
|
||||
library file_sample;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:html';
|
||||
|
||||
import 'package:async_helper/async_helper.dart';
|
||||
import 'package:expect/minitest.dart';
|
||||
|
||||
// Expected output from all functions, asynchronous, and event routines.
|
||||
const String log_results = 'test-first\n' +
|
||||
'acquire START\n' +
|
||||
'acquire CALLBACK START\n' +
|
||||
'acquire CALLBACK END\n' +
|
||||
'first START\n' +
|
||||
'first END\n' +
|
||||
'test-second\n' +
|
||||
'second START\n' +
|
||||
'second END\n' +
|
||||
'reader onLoadEnd event\n' +
|
||||
'file content = XYZZY Output\n';
|
||||
|
||||
// Simple logger to record all output.
|
||||
class Logger {
|
||||
StringBuffer _log = new StringBuffer();
|
||||
|
||||
void log(String message) {
|
||||
_log.writeln(message);
|
||||
}
|
||||
|
||||
String get contents => _log.toString();
|
||||
}
|
||||
|
||||
Logger testLog = new Logger();
|
||||
|
||||
Future<FileSystem> _fileSystem;
|
||||
|
||||
DirectoryEntry _myDirectory;
|
||||
|
||||
Future<FileSystem> get fileSystem async {
|
||||
if (_fileSystem != null) return _fileSystem;
|
||||
|
||||
testLog.log('acquire START');
|
||||
_fileSystem = window.requestFileSystem(100);
|
||||
|
||||
var fs = await _fileSystem;
|
||||
testLog.log('acquire CALLBACK START');
|
||||
expect(fs != null, true);
|
||||
expect(fs.root != null, true);
|
||||
expect(fs.runtimeType, FileSystem);
|
||||
expect(fs.root.runtimeType, DirectoryEntry);
|
||||
testLog.log('acquire CALLBACK END');
|
||||
|
||||
return _fileSystem;
|
||||
}
|
||||
|
||||
Future<FileEntry> createFile() async {
|
||||
var fs = await fileSystem;
|
||||
|
||||
_myDirectory = await fs.root.createDirectory('my_directory');
|
||||
|
||||
FileEntry fileEntry = await _myDirectory.createFile('log.txt');
|
||||
|
||||
expect(fileEntry.isFile, true);
|
||||
expect(fileEntry.name, 'log.txt');
|
||||
expect(fileEntry.fullPath, '/my_directory/log.txt');
|
||||
|
||||
FileWriter writer = await fileEntry.createWriter();
|
||||
|
||||
Blob blob = new Blob(['XYZZY Output'], 'text/plain');
|
||||
|
||||
writer.write(blob);
|
||||
|
||||
var reader = new FileReader();
|
||||
|
||||
var completer = new Completer<String>();
|
||||
|
||||
reader.onLoadEnd.listen((event) {
|
||||
testLog.log('reader onLoadEnd event');
|
||||
dynamic target = event.currentTarget;
|
||||
testLog.log('file content = ${target.result}');
|
||||
expect(target.result, 'XYZZY Output');
|
||||
|
||||
completer.complete(target.result);
|
||||
});
|
||||
|
||||
Blob readBlob = await fileEntry.file();
|
||||
|
||||
reader.readAsText(readBlob);
|
||||
|
||||
// Wait until onLoadEnd if fired.
|
||||
await completer.future;
|
||||
|
||||
return new Future<FileEntry>.value(fileEntry);
|
||||
}
|
||||
|
||||
Future<List<Entry>> readEntries(DirectoryEntry directory) async {
|
||||
DirectoryReader reader = directory.createReader();
|
||||
List<Entry> entries = await reader.readEntries();
|
||||
return entries;
|
||||
}
|
||||
|
||||
Future testFileSystemRequest() async {
|
||||
testLog.log('test-first');
|
||||
var fs = await fileSystem;
|
||||
testLog.log('first START');
|
||||
expect(fs != null, true);
|
||||
expect(fs.root != null, true);
|
||||
expect(fs.runtimeType, FileSystem);
|
||||
expect(fs.root.runtimeType, DirectoryEntry);
|
||||
testLog.log('first END');
|
||||
}
|
||||
|
||||
Future testFileSystemRequestCreateRW() async {
|
||||
testLog.log('test-second');
|
||||
var fs = await fileSystem;
|
||||
testLog.log('second START');
|
||||
expect(fs != null, true);
|
||||
expect(fs.root != null, true);
|
||||
expect(fs.runtimeType, FileSystem);
|
||||
expect(fs.root.runtimeType, DirectoryEntry);
|
||||
testLog.log('second END');
|
||||
|
||||
FileEntry fileEntry = await createFile();
|
||||
expect(fileEntry.name, 'log.txt');
|
||||
|
||||
List<Entry> entries = await readEntries(fs.root);
|
||||
expect(entries.length > 0, true);
|
||||
expect(entries[0].isDirectory, true);
|
||||
expect(entries[0].name, 'my_directory');
|
||||
|
||||
List<Entry> myEntries = await readEntries(_myDirectory);
|
||||
expect(myEntries.length, 1);
|
||||
expect(myEntries[0].isFile, true);
|
||||
expect(myEntries[0].name, 'log.txt');
|
||||
|
||||
// Validate every function, async and event mechanism successfully ran.
|
||||
expect(testLog.contents, log_results);
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncTest(() async {
|
||||
await testFileSystemRequest();
|
||||
await testFileSystemRequestCreateRW();
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue