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 @@ -33,6 +33,8 @@ internal class MatchViewModel @Inject constructor(
private val configManager: ConfigManager,
private val timeHelper: TimeHelper,
) : ViewModel() {
var isMatcherRunning = false
private set
var isInitialized = false
private set
private var candidatesLoaded = 0
Expand All @@ -48,6 +50,8 @@ internal class MatchViewModel @Inject constructor(
private val _matchResponse = MutableLiveData<LiveDataEventWithContent<Serializable>>()

fun setupMatch(params: MatchParams) = viewModelScope.launch {
if (isMatcherRunning) return@launch
isMatcherRunning = true
isInitialized = true
val startTime = timeHelper.now()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,43 @@ internal class MatchViewModelTest {
)
}

@Test
fun `setupMatch does not continue when isMatcherRunning is true`() = runTest {
// Seting up a matcher runs in background
coEvery { faceMatcherUseCase.invoke(any(), any()) } returns flow {
emit(MatcherUseCase.MatcherState.LoadingStarted(1))
emit(MatcherUseCase.MatcherState.CandidateLoaded)
emit(
MatcherUseCase.MatcherState.Success(
matchResultItems = listOf(FaceMatchResult.Item("1", 90f)),
totalCandidates = 1,
matcherName = MATCHER_NAME,
matchBatches = emptyList(),
),
)
}
coJustRun { saveMatchEvent.invoke(any(), any(), any(), any(), any(), any(), any()) }

val states = viewModel.matchState.test()
val matchParams = MatchParams(
probeReferenceId = "referenceId",
probeFaceSamples = listOf(getFaceSample()),
faceSDK = FaceConfiguration.BioSdk.RANK_ONE,
flowType = FlowType.ENROL,
queryForCandidates = mockk {},
biometricDataSource = BiometricDataSource.Simprints,
)

viewModel.setupMatch(matchParams)
assertThat(viewModel.isMatcherRunning).isTrue()
viewModel.setupMatch(matchParams)
advanceUntilIdle()

coVerify(exactly = 1) { faceMatcherUseCase.invoke(any(), any()) }
// Checking that no new states were emitted. History = (NotStarted, LoadingCandidates LoadingCandidates, Finished)
assertThat(states.valueHistory()).hasSize(4)
}

private fun getFaceSample(): MatchParams.FaceSample = MatchParams.FaceSample(UUID.randomUUID().toString(), Random.nextBytes(20))

private fun getFingerprintSample(): MatchParams.FingerprintSample = MatchParams.FingerprintSample(
Expand Down