WebDAV cache: fix problem that sometimes the tests fail

This commit is contained in:
Ricki Hirner 2021-11-10 15:52:57 +01:00
parent 09384948b5
commit 952a10fb3d
4 changed files with 11 additions and 9 deletions

View file

@ -53,6 +53,7 @@ jobs:
- name: Run connected tests
run: ./gradlew app:connectedCheck
- name: Archive results
if: always()
uses: actions/upload-artifact@v2
with:
name: test-results

View file

@ -41,9 +41,7 @@ class DiskCache(
if (!cacheDir.mkdirs())
throw IllegalArgumentException("Couldn't create cache in $cacheDir")
workerScope.launch {
trim()
}
trim()
}

View file

@ -13,7 +13,7 @@ class DiskCacheTest {
companion object {
const val SOME_KEY = "key1"
val SOME_VALUE_LENGTH = 15
const val SOME_VALUE_LENGTH = 15
val SOME_VALUE = ByteArray(SOME_VALUE_LENGTH) { it.toByte() }
val SOME_OTHER_VALUE = ByteArray(30) { (it/2).toByte() }
@ -23,20 +23,19 @@ class DiskCacheTest {
@Rule
@JvmField
val cacheDir = TemporaryFolder()
val tempDir = TemporaryFolder()
lateinit var cache: DiskCache
@Before
fun createCache() {
cacheDir.create()
cache = DiskCache(cacheDir.newFolder(), MAX_CACHE_SIZE)
cache = DiskCache(tempDir.newFolder(), MAX_CACHE_SIZE)
}
@After
fun deleteCache() {
cacheDir.delete()
assertTrue(cache.cacheDir.deleteRecursively())
}
@ -114,7 +113,11 @@ class DiskCacheTest {
@Test
fun testTrim() {
assertEquals(0, cache.entries())
cache.get(SOME_KEY) { SOME_VALUE }
assertEquals(1, cache.entries())
cache.trim()
assertEquals(1, cache.entries())

@ -1 +1 @@
Subproject commit cca734af166e3040c9709b3d01ed68654846c9bf
Subproject commit 5245bc91ca17d789cd826ed716aeebeb814485a7