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 @@ -45,7 +45,11 @@ internal class FallbackToCommCareDataSourceIfNeededUseCase @Inject constructor(
return false
}

Simber.w("Falling back to CommCare data source because threshold is $thresholdMs and last sync was at $lastSyncTime", tag = SYNC)
Simber.w(
message = "Falling back to CommCare data source because threshold is $thresholdMs and last sync was at $lastSyncTime",
t = Exception("Fallback to CommCare just-in-time reading"),
tag = SYNC,
)
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ internal class CommCareEventDataSource @Inject constructor(
}
}

Simber.w("All date parsing attempts failed for: $dateString", tag = COMMCARE_SYNC)
Simber.w(
message = "All date parsing attempts failed for: $dateString",
t = IllegalArgumentException("Could not parse date string"),
tag = COMMCARE_SYNC,
)
return 0L
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ class CommCareEventDataSourceTest {
assertEquals(1, events.size) // Still processes because invalid date defaults to 0L
// Should log error for each format attempt plus final failure warning
verify(atLeast = 2) { Simber.e(any(), ofType<Exception>(), tag = LoggingConstants.CrashReportTag.COMMCARE_SYNC) }
verify { Simber.w(any(), tag = LoggingConstants.CrashReportTag.COMMCARE_SYNC) }
verify { Simber.w(any(), ofType<IllegalArgumentException>(), tag = LoggingConstants.CrashReportTag.COMMCARE_SYNC) }
}

@Test
Expand Down Expand Up @@ -976,7 +976,7 @@ class CommCareEventDataSourceTest {

// Should log date parsing errors
verify(atLeast = 2) { Simber.e(any(), ofType<Exception>(), tag = LoggingConstants.CrashReportTag.COMMCARE_SYNC) }
verify { Simber.w(any(), tag = LoggingConstants.CrashReportTag.COMMCARE_SYNC) }
verify { Simber.w(any(), ofType<IllegalArgumentException>(), tag = LoggingConstants.CrashReportTag.COMMCARE_SYNC) }
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ object Simber {
*/
fun w(
message: String,
t: Throwable? = null,
t: Throwable,
tag: CrashReportTag,
) = w(message, t, tag.name)

fun w(
message: String,
t: Throwable? = null,
t: Throwable,
tag: String = DEFAULT_TAG,
) {
when {
t == null -> Logger.w(message, null, ensureCharactersAreValid(tag))
shouldSkipThrowableReporting(t) -> Logger.i(message, t, ensureCharactersAreValid(tag))
else -> Logger.w(message, t, ensureCharactersAreValid(tag))
if (shouldSkipThrowableReporting(t)) {
Logger.i(message, t, ensureCharactersAreValid(tag))
} else {
Logger.w(message, t, ensureCharactersAreValid(tag))
}
}

Expand Down Expand Up @@ -171,7 +171,7 @@ object Simber {
throw IllegalArgumentException("String must be less than $max characters.")
}

return message.substring(0, max)
return message.take(max)
Comment thread
BurningAXE marked this conversation as resolved.
}
return message
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ class CrashlyticsLogWriterTest {
verify { crashMock.log("[TAG] Test Message") }
}

@Test
fun `should log and record error on WARN priority`() {
val crashMock = mockk<FirebaseCrashlytics>(relaxed = true)
val spyCrashReportingTree = spyk(CrashlyticsLogWriter(crashMock))

Logger.setLogWriters(spyCrashReportingTree)
Simber.w("Test Message", null)

verify {
crashMock.recordException(
match<Exception> { it.message?.contains("Test Message") == true }
)
}
}

@Test
fun `with custom exception should log and record error on WARN priority`() {
val crashMock = mockk<FirebaseCrashlytics>(relaxed = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ class FaceMatcherUseCase @Inject constructor(
): Flow<MatcherState> = channelFlow {
Simber.i("Initialising matcher", tag = crashReportTag)
if (matchParams.bioSdk !is FaceConfiguration.BioSdk) {
Simber.w("Face SDK was not provided", tag = crashReportTag)
Simber.w(
message = "Face SDK was not provided",
t = IllegalArgumentException("Face SDK was not provided"),
tag = crashReportTag,
)
send(MatcherState.Success(emptyList(), emptyList(), 0, ""))
return@channelFlow
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ class FingerprintMatcherUseCase @Inject constructor(
): Flow<MatcherState> = channelFlow {
Simber.i("Initialising matcher", tag = crashReportTag)
if (matchParams.bioSdk !is FingerprintConfiguration.BioSdk) {
Simber.w("Fingerprint SDK was not provided", tag = crashReportTag)
Simber.w(
message = "Fingerprint SDK was not provided",
t = IllegalArgumentException("Fingerprint SDK was not provided"),
tag = crashReportTag,
)
send(MatcherState.Success(emptyList(), emptyList(), 0, ""))
return@channelFlow
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import com.simprints.core.tools.time.TimeHelper
import com.simprints.face.infra.basebiosdk.matching.FaceMatcher
import com.simprints.face.infra.biosdkresolver.ResolveFaceBioSdkUseCase
import com.simprints.infra.config.store.models.FaceConfiguration
import com.simprints.infra.config.store.models.FingerprintConfiguration
import com.simprints.infra.config.store.models.Project
import com.simprints.infra.enrolment.records.repository.EnrolmentRecordRepository
import com.simprints.infra.enrolment.records.repository.domain.models.BiometricDataSource
import com.simprints.infra.enrolment.records.repository.domain.models.SubjectQuery
import com.simprints.infra.logging.LoggingConstants
import com.simprints.infra.logging.Simber
import com.simprints.infra.matching.MatchParams
import com.simprints.testtools.common.coroutines.TestCoroutineRule
import io.mockk.*
Expand Down Expand Up @@ -130,6 +133,52 @@ internal class FaceMatcherUseCaseTest {
)
}

@Test
fun `Logs warning and returns empty success when wrong SDK type is provided`() = runTest {
mockkObject(Simber)
justRun { Simber.w(message = any<String>(), t = any<Throwable>(), tag = any<String>()) }

val results = useCase
.invoke(
MatchParams(
probeReferenceId = "referenceId",
probeSamples = listOf(
CaptureSample(
captureEventId = "faceId",
template = byteArrayOf(1, 2, 3),
modality = Modality.FACE,
format = "format",
),
),
bioSdk = FingerprintConfiguration.BioSdk.SECUGEN_SIM_MATCHER, // Wrong SDK type
flowType = FlowType.VERIFY,
queryForCandidates = SubjectQuery(),
biometricDataSource = BiometricDataSource.Simprints,
),
project,
).toList()

verify {
Simber.w(
message = "Face SDK was not provided",
t = ofType<IllegalArgumentException>(),
tag = LoggingConstants.CrashReportTag.FACE_MATCHING,
)
}

assertThat(results).containsExactly(
MatcherUseCase.MatcherState.Success(
comparisonResults = emptyList(),
totalCandidates = 0,
matcherName = "",
matchBatches = emptyList(),
),
)

coVerify(exactly = 0) { faceMatcher.getHighestComparisonScoreForCandidate(any()) }
unmockkObject(Simber)
}

@Test
fun `Correctly calls SDK matcher`() = runTest {
val totalCandidates = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import com.simprints.core.tools.time.TimeHelper
import com.simprints.core.tools.time.Timestamp
import com.simprints.fingerprint.infra.biosdk.BioSdkWrapper
import com.simprints.fingerprint.infra.biosdk.ResolveBioSdkWrapperUseCase
import com.simprints.infra.config.store.models.FaceConfiguration
import com.simprints.infra.config.store.models.FingerprintConfiguration.BioSdk.SECUGEN_SIM_MATCHER
import com.simprints.infra.config.store.models.Project
import com.simprints.infra.config.sync.ConfigManager
import com.simprints.infra.enrolment.records.repository.EnrolmentRecordRepository
import com.simprints.infra.enrolment.records.repository.domain.models.BiometricDataSource
import com.simprints.infra.enrolment.records.repository.domain.models.IdentityBatch
import com.simprints.infra.enrolment.records.repository.domain.models.SubjectQuery
import com.simprints.infra.logging.LoggingConstants
import com.simprints.infra.logging.Simber
import com.simprints.infra.matching.MatchParams
import com.simprints.testtools.common.coroutines.TestCoroutineRule
import io.mockk.*
Expand Down Expand Up @@ -147,6 +150,53 @@ internal class FingerprintMatcherUseCaseTest {
)
}

@Test
fun `Logs warning and returns empty success when wrong SDK type is provided`() = runTest {
mockkObject(Simber)
justRun { Simber.w(message = any<String>(), t = any<Throwable>(), tag = any<String>()) }

val results = useCase
.invoke(
MatchParams(
probeReferenceId = "referenceId",
probeSamples = listOf(
CaptureSample(
captureEventId = "fingerprintId",
template = byteArrayOf(1, 2, 3),
modality = Modality.FINGERPRINT,
format = "format",
identifier = SampleIdentifier.LEFT_3RD_FINGER,
),
),
bioSdk = FaceConfiguration.BioSdk.RANK_ONE, // Wrong SDK type
flowType = FlowType.VERIFY,
queryForCandidates = SubjectQuery(),
biometricDataSource = BiometricDataSource.Simprints,
),
project,
).toList()

verify {
Simber.w(
message = "Fingerprint SDK was not provided",
t = ofType<IllegalArgumentException>(),
tag = LoggingConstants.CrashReportTag.FINGER_MATCHING,
)
}

assertThat(results).containsExactly(
MatcherUseCase.MatcherState.Success(
comparisonResults = emptyList(),
totalCandidates = 0,
matcherName = "",
matchBatches = emptyList(),
),
)

coVerify(exactly = 0) { bioSdkWrapper.match(any(), any(), any()) }
unmockkObject(Simber)
}

@Test
fun `Correctly calls SDK matcher`() = runTest {
coEvery { enrolmentRecordRepository.count(any(), any()) } returns 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private fun NavController.navigateIfPossible(
} else {
val fragmentName = currentFragment.toString().takeWhile { it != ' ' }
val target = (currentDestination as? FragmentNavigator.Destination)?.className
Simber.w("Cannot navigate from $fragmentName to $target")
Simber.w("Cannot navigate from $fragmentName to $target", t = IllegalStateException("Navigation not possible"))
}
}

Expand Down