-
Notifications
You must be signed in to change notification settings - Fork 214
Simplify Filesystem
, introduce TestReaderWriter
#3873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
PR Health |
1a6c8b1
to
f6b0048
Compare
Filesystem
, introduce TestReaderWriter
Move `FilesystemCache` and `AssetPathProvider` out of `Filesystem` and into the `Reader` classes.
f6b0048
to
cb8fc64
Compare
build/lib/src/state/filesystem.dart
Outdated
: cache = cache ?? const PassthroughFilesystemCache(), | ||
assets = {}; | ||
@override | ||
Future<bool> exists(String path) async => _files.containsKey(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will be faster to have these not be async and return Future.value(whatnot)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
AssetId('example', 'web/initial.txt'), | ||
'initial', | ||
) | ||
..filesystem.writeAsStringSync( | ||
..testing.writeString( | ||
AssetId('example', 'web/large.txt'), | ||
List.filled(10000, 'large').join(''), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is not new code, but isn't this just 'large' * 10000
? (as in literally that code will give the same string).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is, done :)
@@ -1489,9 +1489,9 @@ void main() { | |||
); | |||
|
|||
// Followup build with modified inputs. | |||
var serializedGraph = | |||
result.readerWriter.assets[makeAssetId('a|$assetGraphPath')]!; | |||
result.readerWriter.assets.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the story on the clear? Here it's replaced by nothing --- below it's replaced by a delete
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most of the test cases, like this one, the next run passes the same sources again, so the clear had no effect.
Only cases where the second run wants there to be fewer files actually needs a clear or delete, so now, that's what the tests do :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
AssetId('example', 'web/initial.txt'), | ||
'initial', | ||
) | ||
..filesystem.writeAsStringSync( | ||
..testing.writeString( | ||
AssetId('example', 'web/large.txt'), | ||
List.filled(10000, 'large').join(''), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is, done :)
build/lib/src/state/filesystem.dart
Outdated
: cache = cache ?? const PassthroughFilesystemCache(), | ||
assets = {}; | ||
@override | ||
Future<bool> exists(String path) async => _files.containsKey(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -1489,9 +1489,9 @@ void main() { | |||
); | |||
|
|||
// Followup build with modified inputs. | |||
var serializedGraph = | |||
result.readerWriter.assets[makeAssetId('a|$assetGraphPath')]!; | |||
result.readerWriter.assets.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most of the test cases, like this one, the next run passes the same sources again, so the clear had no effect.
Only cases where the second run wants there to be fewer files actually needs a clear or delete, so now, that's what the tests do :)
For #3811, work in progress.
Move
FilesystemCache
out ofFilesystem
toFileBasedAssetReader
andInMemoryAssetReaderWriter
.Filesystem
now just always directly reads/writes.Move
AssetPathProvider
out ofFilesystem
toFileBasedAssetReader
andInMemoryAssetReaderWriter
.Filesystem
now accesses files by path, with theReader
handling the mapping from IDs to path. This removes the last big difference betweenInMemoryAssetReaderWriter
andFileBasedAssetReader
, which was that the in-memory version used did not map to paths, storing data by ID.Add
TestReaderWriter
withReaderWriterTesting
member that gives access to the internal state for testing;InMemoryAssetReaderWriter
and itsFilesystem
and otherAssetReaderState
members are now hidden from tests behind this test-specific API.