Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ object IpConfigKtorClient {

fun create(
engineFactory: HttpClientEngineFactory<HttpClientEngineConfig> = OkHttp,
) = HttpClient(engineFactory) { applyForIpConfig() }
includeTimeout: Boolean = true,
) = HttpClient(engineFactory) { applyForIpConfig(includeTimeout = includeTimeout) }

fun create(
engine: HttpClientEngine,
) = HttpClient(engine) { applyForIpConfig() }
includeTimeout: Boolean = true,
) = HttpClient(engine) { applyForIpConfig(includeTimeout = includeTimeout) }

private fun HttpClientConfig<*>.applyForIpConfig() {
private fun HttpClientConfig<*>.applyForIpConfig(includeTimeout: Boolean) {
install(ContentNegotiation) {
json(
Json {
Expand All @@ -35,10 +37,12 @@ object IpConfigKtorClient {
}
)
}
install(HttpTimeout) {
socketTimeoutMillis = Timeout.inWholeMilliseconds
requestTimeoutMillis = Timeout.inWholeMilliseconds
connectTimeoutMillis = Timeout.inWholeMilliseconds
if (includeTimeout) {
install(HttpTimeout) {
socketTimeoutMillis = Timeout.inWholeMilliseconds
requestTimeoutMillis = Timeout.inWholeMilliseconds
connectTimeoutMillis = Timeout.inWholeMilliseconds
}
}
defaultRequest {
contentType(ContentType.Application.Json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import io.ktor.client.request.get
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpStatusCode
import io.ktor.http.headersOf
import io.ktor.utils.io.ByteReadChannel
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
Expand Down Expand Up @@ -105,14 +104,10 @@ internal class IpConfigWanInfoRepositoryTest {
country = Country(
name = "United States",
iso = "US",
),
region = Region(
), region = Region(
name = "New Jersey",
code = "NJ",
),
zipCode = ZipCode("08601"),
cityName = "Trenton",
location = Location(
), zipCode = ZipCode("08601"), cityName = "Trenton", location = Location(
latitude = 40.2206,
longitude = -74.7597,
)
Expand Down Expand Up @@ -146,56 +141,53 @@ internal class IpConfigWanInfoRepositoryTest {
}

@Test
fun `retry when UnknownHostException received`() =
runTest(ioDispatcher) {
val query: HttpQuery = mockk {
coEvery { this@mockk.invoke(IpConfigUrl.Main) } throws UnknownHostException("Test")
}
val repo = IpConfigWanInfoRepository(ioDispatcher, query)

val result = repo.loadWanInfo()
assertThat(result).isEqualTo(WanInfoRepository.Result.Error)
coVerify(exactly = 2) { query.invoke(IpConfigUrl.Main) }
fun `retry when UnknownHostException received`() = runTest(ioDispatcher) {
val query: HttpQuery = mockk {
coEvery { this@mockk.invoke(IpConfigUrl.Main) } throws UnknownHostException("Test")
}
val repo = IpConfigWanInfoRepository(ioDispatcher, query)

@Test
fun `retry when ConnectException received`() =
runTest(ioDispatcher) {
val query: HttpQuery = mockk {
coEvery { this@mockk.invoke(IpConfigUrl.Main) } throws ConnectException("Test")
}
val repo = IpConfigWanInfoRepository(ioDispatcher, query)
val result = repo.loadWanInfo()
assertThat(result).isEqualTo(WanInfoRepository.Result.Error)
coVerify(exactly = 2) { query.invoke(IpConfigUrl.Main) }
}

val result = repo.loadWanInfo()
assertThat(result).isEqualTo(WanInfoRepository.Result.Error)
coVerify(exactly = 2) { query.invoke(IpConfigUrl.Main) }
@Test
fun `retry when ConnectException received`() = runTest(ioDispatcher) {
val query: HttpQuery = mockk {
coEvery { this@mockk.invoke(IpConfigUrl.Main) } throws ConnectException("Test")
}
val repo = IpConfigWanInfoRepository(ioDispatcher, query)

@Test
fun `not retry when generic exception received`() =
runTest(ioDispatcher) {
val query: HttpQuery = mockk {
coEvery { this@mockk.invoke(IpConfigUrl.Main) } throws IllegalStateException("Test")
}
val repo = IpConfigWanInfoRepository(ioDispatcher, query)
val result = repo.loadWanInfo()
assertThat(result).isEqualTo(WanInfoRepository.Result.Error)
coVerify(exactly = 2) { query.invoke(IpConfigUrl.Main) }
}

val result = repo.loadWanInfo()
assertThat(result).isEqualTo(WanInfoRepository.Result.Error)
coVerify(exactly = 1) { query.invoke(IpConfigUrl.Main) }
@Test
fun `not retry when generic exception received`() = runTest(ioDispatcher) {
val query: HttpQuery = mockk {
coEvery { this@mockk.invoke(IpConfigUrl.Main) } throws IllegalStateException("Test")
}
val repo = IpConfigWanInfoRepository(ioDispatcher, query)

val result = repo.loadWanInfo()
assertThat(result).isEqualTo(WanInfoRepository.Result.Error)
coVerify(exactly = 1) { query.invoke(IpConfigUrl.Main) }
}

private fun create(
bodyContent: String,
statusCode: HttpStatusCode,
): IpConfigWanInfoRepository {
val mockEngine = MockEngine {
val mockEngine = MockEngine { _ ->
respond(
content = ByteReadChannel(bodyContent),
content = bodyContent,
status = statusCode,
headers = headersOf(HttpHeaders.ContentType, "application/json")
)
}
val client = IpConfigKtorClient.create(mockEngine)
val client = IpConfigKtorClient.create(mockEngine, includeTimeout = false)
val query = HttpQuery { url -> client.get(url) }
return IpConfigWanInfoRepository(ioDispatcher, query)
}
Expand Down
22 changes: 11 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
[versions]
androidGradlePlugin = "9.2.1"
androidxActivity = "1.11.0"
androidxLifecycle = "2.9.4"
androidxActivity = "1.13.0"
androidxLifecycle = "2.10.0"
androidxCoreTest = "1.7.0"
assertk = "0.28.1"
composeBom = "2026.05.01"
composeNavigation = "2.9.5"
composeNavigation = "2.9.8"
dagger = "2.59.2"
kotlinMetadata = "2.4.0"
dependencyAnalysis = "3.2.0"
dependencyAnalysis = "3.15.0"
googleAccompanist = "0.36.0"
googleGuava = "33.5.0-jre"
googleMaterial = "1.13.0"
googleGuava = "33.6.0-jre"
googleMaterial = "1.14.0"
javapoet = "1.13.0"
junit4 = "4.13.2"
junitJupiterBom = "6.0.0"
junitJupiterBom = "6.1.0"
kotlin = "2.4.0"
kotlinCoroutines = "1.11.0"
kotlinSerialization = "1.11.0"
# KSP version must align with Kotlin version: https://github.com/google/ksp/releases
ksp = "2.3.9"
ktor = "3.3.1"
lottie = "6.6.10"
mockk = "1.14.6"
robolectric = "4.16"
ktor = "3.5.0"
lottie = "6.7.1"
mockk = "1.14.11"
robolectric = "4.16.1"
turbine = "1.2.1"


Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 10 additions & 21 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.