You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So... I use Jimfs in my tests and I reckon that's what many people do. I think it'd be fruitful if Jimfs could detect open resources that aren't released properly (by resources I mean anything created by the FS that's implementing Closeable, including channels, directory streams, etc...). This makes it really easy to ensure tested components properly close file resources. I realize it'll be silly if this suddenly became the default behavior, so I'd expect this to be explicitly enabled in the FS's Configuration. It'd be preferable if this could be checked in FileSystem::close, so the following pattern can be utilized (depending on the testing framework):
privateFileSystemfs;
@BeforeEachvoidsetUp() {
varconfig = Configuration.builder(PathType.unix()).setDetectLeaksOnClosure(true).build();
fs = Jimfs.newFileSystem(config);
}
@AfterEachvoidtearDown() throwsIOException {
if (fs != null) {
fs.close(); // Throws in case of resource leaks
}
}
...
I notice resource registration is handled by the FileSystemState class. Currently, it seems to only close registered resources. I think most behavior could be implemented there, but you guys know better. The class seems to receive possibly custom Closeable instances, so it may need to check the classes of registered resources before complaining. Perhaps, specific resource types could explicitly opt-in for the checks by the configuration (e.g. only check FileChannels).
Thanks in advance!
The text was updated successfully, but these errors were encountered:
Hi! First of all, thanks for this library 👍🏾.
So... I use Jimfs in my tests and I reckon that's what many people do. I think it'd be fruitful if Jimfs could detect open resources that aren't released properly (by resources I mean anything created by the FS that's implementing
Closeable
, including channels, directory streams, etc...). This makes it really easy to ensure tested components properly close file resources. I realize it'll be silly if this suddenly became the default behavior, so I'd expect this to be explicitly enabled in the FS'sConfiguration
. It'd be preferable if this could be checked inFileSystem::close
, so the following pattern can be utilized (depending on the testing framework):I notice resource registration is handled by the
FileSystemState
class. Currently, it seems to only close registered resources. I think most behavior could be implemented there, but you guys know better. The class seems to receive possibly customCloseable
instances, so it may need to check the classes of registered resources before complaining. Perhaps, specific resource types could explicitly opt-in for the checks by the configuration (e.g. only check FileChannels).Thanks in advance!
The text was updated successfully, but these errors were encountered: