fix(infrared): add cutoff timestamp to failInterruptedLearning to prevent race with subsequent tasks
This commit is contained in:
+2
-1
@@ -100,11 +100,12 @@ class FakeInfraredKeyRepository : InfraredKeyRepository {
|
||||
|
||||
override suspend fun failInterruptedLearning(
|
||||
profileId: ProviderProfileId,
|
||||
cutoffEpochMillis: Long,
|
||||
updatedAtEpochMillis: Long,
|
||||
): DomainResult<Int> = synchronized(lock) {
|
||||
var changed = 0
|
||||
keys.replaceAll { _, key ->
|
||||
if (key.profileId == profileId && key.status == InfraredKeyStatus.LEARNING) {
|
||||
if (key.profileId == profileId && key.status == InfraredKeyStatus.LEARNING && key.createdAtEpochMillis <= cutoffEpochMillis) {
|
||||
changed += 1
|
||||
key.copy(
|
||||
status = InfraredKeyStatus.FAILED,
|
||||
|
||||
+35
@@ -207,6 +207,41 @@ class FakeInfraredKeyRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun failInterruptedLearningRespectsCutoffEpochMillis() = runTest {
|
||||
val repository = FakeInfraredKeyRepository()
|
||||
repository.insert(
|
||||
savedKey(
|
||||
id = "old-learning",
|
||||
sdkKey = "old-learning",
|
||||
status = InfraredKeyStatus.LEARNING,
|
||||
).copy(createdAtEpochMillis = 100L),
|
||||
)
|
||||
repository.insert(
|
||||
savedKey(
|
||||
id = "new-learning",
|
||||
sdkKey = "new-learning",
|
||||
status = InfraredKeyStatus.LEARNING,
|
||||
).copy(createdAtEpochMillis = 200L),
|
||||
)
|
||||
|
||||
val result = repository.failInterruptedLearning(
|
||||
profileId = profileOne,
|
||||
cutoffEpochMillis = 150L,
|
||||
updatedAtEpochMillis = 150L,
|
||||
)
|
||||
|
||||
assertEquals(DomainResult.Success(1), result)
|
||||
assertEquals(
|
||||
InfraredKeyStatus.FAILED,
|
||||
repository.successfulKey(InfraredKeyRef(profileOne, InfraredKeyId("old-learning")))?.status,
|
||||
)
|
||||
assertEquals(
|
||||
InfraredKeyStatus.LEARNING,
|
||||
repository.successfulKey(InfraredKeyRef(profileOne, InfraredKeyId("new-learning")))?.status,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun deviceConfigurationIsIsolatedByProfile() = runTest {
|
||||
val repository = FakeInfraredDeviceConfigurationRepository()
|
||||
|
||||
Reference in New Issue
Block a user