Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the new CVR export functions in libs/backend up to 100% code coverage #4090

Merged
merged 12 commits into from
Oct 24, 2023

Conversation

arsalansufi
Copy link
Contributor

@arsalansufi arsalansufi commented Oct 12, 2023

Easiest reviewed by commit

Overview

Issue link: #4058

Finally adding the tests that I've punted on for so so long. This PR gets the new CVR export functions in libs/backend up to 💯% code coverage. I'll be opening a separate PR for the new CVR import functions.

import { configureApp } from '../../../test/helpers/shared_helpers';
import { scanBallot, withApp } from '../../../test/helpers/custom_helpers';
import { configureApp } from '../test/helpers/shared_helpers';
import { scanBallot, withApp } from '../test/helpers/custom_helpers';
Copy link
Contributor Author

@arsalansufi arsalansufi Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An unrelated change. Just had a hunch that app_config.test.ts wasn't intentionally located inside apps/scan/backed/src/scanners/custom/. The other tests in apps/scan/backed/src/scanners/custom/ are all about scanning and prefixed with app_scan_*. Moved it up alongside other more general tests in apps/scan/backend/src/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not intentionally there, it's bothered me but I hadn't moved it. Thanks!

@@ -74,6 +75,7 @@ export function createMockUsbDrive(): MockUsbDrive {
removeUsbDrive() {
mockUsbTmpDir?.removeCallback();
mockUsbTmpDir = undefined;
usbDrive.status.reset();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without these resets, inserting and removing the mock USB drive continues growing the list of expected repeated calls. This results in unexpected behavior like the mock USB drive indicating that it's no drive even after calling mockUsbDrive.insertUsbDrive

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, thank you. @jonahkagan and I been discussing this behavior and had decided to live with it, but I like this approach.

It's really only a problem on removing, because on insertion, there should always be some status polling. Otherwise, why insert the USB drive? But I'm fine resetting on both for consistency.

const exportDirectoryName = scannerStore.getExportDirectoryName();
if (!exportDirectoryName) {
return true;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you're wondering why this check has moved location and gone from checking false to true, this check, at its previous location, was almost equivalent to the ballotsCounted === 0 check (since we create the export directory after the first ballot is counted).

Now, by moving it after the ballotsCounted === 0 case, we're catching the case that we fail to create the export directory (and specifically save its path in the DB) after the first ballot is counted. Should be exceedingly rare but, regardless, the new check is more useful than the previous one.

If you want to get extra specific, technically the areOrWereCastVoteRecordsBeingExportedToUsbDrive(usbDriveStatus) would likely also catch this. But that check involves a marker file on the USB drive. If the USB drive were replaced with a blank USB drive, that check wouldn't catch anything (other checks after would).

Zooming out, we're talking about the edgiest of edge cases here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🖤

@arsalansufi arsalansufi requested a review from adghayes October 12, 2023 21:34
@arsalansufi arsalansufi marked this pull request as ready for review October 12, 2023 21:34
@arsalansufi arsalansufi requested review from jonahkagan and a team as code owners October 12, 2023 21:34
@arsalansufi arsalansufi requested review from eventualbuddha and removed request for a team, jonahkagan and eventualbuddha October 12, 2023 21:34
import { configureApp } from '../../../test/helpers/shared_helpers';
import { scanBallot, withApp } from '../../../test/helpers/custom_helpers';
import { configureApp } from '../test/helpers/shared_helpers';
import { scanBallot, withApp } from '../test/helpers/custom_helpers';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not intentionally there, it's bothered me but I hadn't moved it. Thanks!

@@ -74,6 +75,7 @@ export function createMockUsbDrive(): MockUsbDrive {
removeUsbDrive() {
mockUsbTmpDir?.removeCallback();
mockUsbTmpDir = undefined;
usbDrive.status.reset();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, thank you. @jonahkagan and I been discussing this behavior and had decided to live with it, but I like this approach.

It's really only a problem on removing, because on insertion, there should always be some status polling. Otherwise, why insert the USB drive? But I'm fine resetting on both for consistency.

const exportDirectoryName = scannerStore.getExportDirectoryName();
if (!exportDirectoryName) {
return true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🖤

@arsalansufi arsalansufi merged commit 00770e6 into main Oct 24, 2023
@arsalansufi arsalansufi deleted the arsalan/cvr-testing branch October 24, 2023 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants