Skip to content

Commit

Permalink
fix: update session timed out error handling (#65)
Browse files Browse the repository at this point in the history
* fix: update session timed out error to be non-blocking

* chore: remove duplicate code

* chore: fix failed timed out unit test
  • Loading branch information
phantumcode authored Oct 20, 2023
1 parent 1ea01cb commit 37ab633
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ extension FaceLivenessDetectionViewModel: FaceDetectionResultHandler {
noFitStartTime = Date()
}
if let elapsedTime = noFitStartTime?.timeIntervalSinceNow, abs(elapsedTime) >= noFitTimeoutInterval {
self.livenessState
.unrecoverableStateEncountered(.timedOut)
self.captureSession.stopRunning()
handleSessionTimedOut()
}
}

Expand All @@ -100,9 +98,7 @@ extension FaceLivenessDetectionViewModel: FaceDetectionResultHandler {
noFitStartTime = Date()
}
if let elapsedTime = noFitStartTime?.timeIntervalSinceNow, abs(elapsedTime) >= noFitTimeoutInterval {
self.livenessState
.unrecoverableStateEncountered(.timedOut)
self.captureSession.stopRunning()
handleSessionTimedOut()
}
}

Expand Down Expand Up @@ -130,4 +126,12 @@ extension FaceLivenessDetectionViewModel: FaceDetectionResultHandler {
}
}
}

private func handleSessionTimedOut() {
DispatchQueue.main.async {
self.livenessState
.unrecoverableStateEncountered(.timedOut)
self.captureSession.stopRunning()
}
}
}
2 changes: 2 additions & 0 deletions Tests/FaceLivenessTests/LivenessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ final class FaceLivenessDetectionViewModelTestCase: XCTestCase {
XCTAssertNotEqual(self.viewModel.livenessState.state, .encounteredUnrecoverableError(.timedOut))
try await Task.sleep(seconds: 1)
self.viewModel.handleNoFaceFit(instruction: .tooFar(nearnessPercentage: 0.2), percentage: 0.2)
try await Task.sleep(seconds: 1)
XCTAssertEqual(self.viewModel.livenessState.state, .encounteredUnrecoverableError(.timedOut))
}

Expand All @@ -168,6 +169,7 @@ final class FaceLivenessDetectionViewModelTestCase: XCTestCase {
XCTAssertNotEqual(self.viewModel.livenessState.state, .encounteredUnrecoverableError(.timedOut))
try await Task.sleep(seconds: 1)
self.viewModel.handleNoFaceDetected()
try await Task.sleep(seconds: 1)
XCTAssertEqual(self.viewModel.livenessState.state, .encounteredUnrecoverableError(.timedOut))
}
}

0 comments on commit 37ab633

Please sign in to comment.