Permormance improvements

This commit is contained in:
Koitharu
2023-04-28 16:22:43 +03:00
parent f9a1d1617e
commit 5ea0ecbd12
56 changed files with 370 additions and 422 deletions

View File

@@ -1,33 +0,0 @@
package org.koitharu.kotatsu.core.github
import kotlinx.coroutines.test.runTest
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.internal.headersContentLength
import org.junit.Assert
import org.junit.Test
import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.parsers.util.await
class AppUpdateRepositoryTest {
private val okHttpClient = OkHttpClient()
private val repository = AppUpdateRepository(okHttpClient)
@Test
fun getLatestVersion() = runTest {
val version = repository.getLatestVersion()
val versionId = VersionId(version.name)
val apkHead = okHttpClient.newCall(
Request.Builder()
.url(version.apkUrl)
.head()
.build(),
).await()
Assert.assertTrue(versionId <= VersionId(BuildConfig.VERSION_NAME))
Assert.assertTrue(apkHead.isSuccessful)
Assert.assertEquals(version.apkSize, apkHead.headersContentLength())
}
}

View File

@@ -1,7 +1,13 @@
package org.koitharu.kotatsu.utils
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.withTimeout
import kotlinx.coroutines.withTimeoutOrNull
import kotlinx.coroutines.yield
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
@@ -27,6 +33,7 @@ class CompositeMutexTest {
}
}
yield()
assertEquals(1, mutex.size)
mutex.unlock(1)
val tryLock = withTimeoutOrNull(1000) {
mutex.lock(1)
@@ -49,4 +56,4 @@ class CompositeMutexTest {
job.cancelAndJoin()
}
}
}
}