[PM-23710] Fixed logic to getServerConfig and added new test on Authenticator (#5518)

This commit is contained in:
aj-rosado
2025-07-11 15:03:48 +01:00
committed by GitHub
parent 557c5b46a5
commit 37af6a1773
2 changed files with 29 additions and 5 deletions

View File

@@ -35,11 +35,11 @@ internal class ServerConfigRepositoryImpl(
override suspend fun getServerConfig(forceRefresh: Boolean): ServerConfig? {
val localConfig = configDiskSource.serverConfig
val needsRefresh = localConfig == null ||
Instant
.ofEpochMilli(localConfig.lastSync)
.isAfter(
clock.instant().plusSeconds(MINIMUM_CONFIG_SYNC_INTERVAL_SEC),
)
clock.instant().isAfter(
Instant
.ofEpochMilli(localConfig.lastSync)
.plusSeconds(MINIMUM_CONFIG_SYNC_INTERVAL_SEC),
)
if (needsRefresh || forceRefresh) {
configService

View File

@@ -119,6 +119,30 @@ class ServerConfigRepositoryTest {
assertEquals(fakeConfigDiskSource.serverConfig, awaitItem())
}
}
@Suppress("MaxLineLength")
@Test
fun `serverConfigStateFlow should fetch new server configurations when minimum config sync interval is reached `() =
runTest {
val testConfig = SERVER_CONFIG.copy(
lastSync = fixedClock.instant().minusSeconds(60 * 60 + 1).toEpochMilli(),
serverData = CONFIG_RESPONSE_JSON.copy(
version = "old version!!",
),
)
fakeConfigDiskSource.serverConfig = testConfig
coEvery {
configService.getConfig()
} returns CONFIG_RESPONSE_JSON.asSuccess()
repository.getServerConfig(forceRefresh = false)
repository.serverConfigStateFlow.test {
assertNotEquals(testConfig, awaitItem())
}
}
}
private val SERVER_CONFIG = ServerConfig(