-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Fix cache file open bugs #7625
Merged
Merged
Fix cache file open bugs #7625
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7499226
Testing cache closes
yschimke e499080
More test fixes
yschimke e263edd
More test fixes
yschimke b83b9eb
More test fixes
yschimke 5ff3cac
Fix more tests
yschimke 6c9a8b4
Fix more tests
yschimke dea78fa
Fix tests
yschimke f9789c1
Merge branch 'master' into check_cache_closes
yschimke 3fee79d
Review comments
yschimke dc5c35e
Cleanup
yschimke 91bb3d4
Reverts
yschimke ee8adcd
Merge branch 'master' into check_cache_closes
yschimke 4ef928b
Okio use
yschimke File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,9 +70,10 @@ class DiskLruCacheTest { | |
} | ||
|
||
private fun createNewCacheWithSize(maxSize: Int) { | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, maxSize.toLong(), taskRunner) | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, maxSize.toLong(), taskRunner).also { | ||
toClose.add(it) | ||
} | ||
synchronized(cache) { cache.initialize() } | ||
toClose.add(cache) | ||
} | ||
|
||
fun setUp(baseFilesystem: FileSystem, windows: Boolean) { | ||
|
@@ -95,8 +96,7 @@ class DiskLruCacheTest { | |
} | ||
taskFaker.close() | ||
|
||
// TODO uncomment after fixing up snapshot calls in this test | ||
// (filesystem.delegate as? FakeFileSystem)?.checkNoOpenFiles() | ||
(filesystem.delegate as? FakeFileSystem)?.checkNoOpenFiles() | ||
} | ||
|
||
@ParameterizedTest | ||
|
@@ -122,8 +122,9 @@ class DiskLruCacheTest { | |
// Simulate a severe Filesystem failure on the first initialization. | ||
filesystem.setFaultyDelete(cacheDir / "k1.0.tmp", true) | ||
filesystem.setFaultyDelete(cacheDir, true) | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner) | ||
toClose.add(cache) | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner).also { | ||
toClose.add(it) | ||
} | ||
try { | ||
cache["k1"] | ||
fail("") | ||
|
@@ -1134,7 +1135,9 @@ class DiskLruCacheTest { | |
setUp(parameters.first, parameters.second) | ||
cache.close() | ||
val dir = (cacheDir / "testOpenCreatesDirectoryIfNecessary").also { filesystem.createDirectories(it) } | ||
cache = DiskLruCache(filesystem, dir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner) | ||
cache = DiskLruCache(filesystem, dir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner).also { | ||
toClose.add(it) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this idiom! |
||
} | ||
set("a", "a", "a") | ||
assertThat(filesystem.exists(dir / "a.0")).isTrue() | ||
assertThat(filesystem.exists(dir / "a.1")).isTrue() | ||
|
@@ -1200,11 +1203,12 @@ class DiskLruCacheTest { | |
cache.close() | ||
createNewCacheWithSize(10) | ||
set("a", "aa", "aaa") // size 5 | ||
val snapshot = cache["a"]!! | ||
set("b", "bb", "bbb") // size 5 | ||
set("c", "cc", "ccc") // size 5; will evict 'A' | ||
cache.flush() | ||
assertThat(snapshot.edit()).isNull() | ||
cache["a"]!!.use { | ||
set("b", "bb", "bbb") // size 5 | ||
set("c", "cc", "ccc") // size 5; will evict 'A' | ||
cache.flush() | ||
assertThat(it.edit()).isNull() | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
|
@@ -1530,8 +1534,9 @@ class DiskLruCacheTest { | |
fun isClosed_uninitializedCache(parameters: Pair<FileSystem, Boolean>) { | ||
setUp(parameters.first, parameters.second) | ||
// Create an uninitialized cache. | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner) | ||
toClose.add(cache) | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner).also { | ||
toClose.add(it) | ||
} | ||
assertThat(cache.isClosed()).isFalse() | ||
cache.close() | ||
assertThat(cache.isClosed()).isTrue() | ||
|
@@ -1554,7 +1559,9 @@ class DiskLruCacheTest { | |
|
||
// Confirm that the fault didn't corrupt entries stored before the fault was introduced. | ||
cache.close() | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner) | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner).also { | ||
toClose.add(it) | ||
} | ||
assertValue("a", "a", "a") | ||
assertValue("b", "b", "b") | ||
assertAbsent("c") | ||
|
@@ -1585,7 +1592,9 @@ class DiskLruCacheTest { | |
|
||
// Confirm that the fault didn't corrupt entries stored before the fault was introduced. | ||
cache.close() | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner) | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner).also { | ||
toClose.add(it) | ||
} | ||
assertValue("a", "a", "a") | ||
assertValue("b", "b", "b") | ||
assertAbsent("c") | ||
|
@@ -1612,7 +1621,9 @@ class DiskLruCacheTest { | |
|
||
// Confirm that the fault didn't corrupt entries stored before the fault was introduced. | ||
cache.close() | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner) | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner).also { | ||
toClose.add(it) | ||
} | ||
assertValue("a", "a", "a") | ||
assertValue("b", "b", "b") | ||
assertAbsent("c") | ||
|
@@ -1633,7 +1644,9 @@ class DiskLruCacheTest { | |
// Confirm that the entry was still removed. | ||
filesystem.setFaultyWrite(journalFile, false) | ||
cache.close() | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner) | ||
cache = DiskLruCache(filesystem, cacheDir, appVersion, 2, Int.MAX_VALUE.toLong(), taskRunner).also { | ||
toClose.add(it) | ||
} | ||
assertAbsent("a") | ||
assertValue("b", "b", "b") | ||
} | ||
|
@@ -1973,6 +1986,7 @@ class DiskLruCacheTest { | |
assertThat(snapshotAfterCommit.hasNext()).withFailMessage( | ||
"Entry has been removed during creation." | ||
).isTrue() | ||
snapshotAfterCommit.next().close() | ||
} | ||
|
||
@ParameterizedTest | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is the goal of this review.
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.
Nice