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

Test for DB queries #127

Merged
merged 22 commits into from
Jun 30, 2024
Merged

Test for DB queries #127

merged 22 commits into from
Jun 30, 2024

Conversation

umbernhard
Copy link
Collaborator

No description provided.

Copy link
Member

@vteague vteague left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for filling all those tests in.

@@ -109,10 +109,8 @@ public static Set<Contest> forCounty(final County the_county) {
public static void deleteForCounty(final Long the_county_id) {
final Set<Contest> contests =
forCounty(Persistence.getByID(the_county_id, County.class));
if (contests != null) {
Copy link
Member

Choose a reason for hiding this comment

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

I really like the idea of going through everything and changing it from something/null with null checks to Optional(something or nothing) with .ispresent checks. I'm just a little unsure about this particular case - are you sure you changed forCounty so that it can never return null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are completely right, it definitely can. I even have a test for it higher up! 🤦

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have now put this back, and also changed the function to return a count of how many contests it deletes so transient DB errors can be detected.

@@ -204,8 +204,9 @@ Find the batch(bmi) that would hold the sequence number given.
cq.select(root).where(cb.and(disjuncts.toArray(new Predicate[disjuncts.size()])));
final TypedQuery<BallotManifestInfo> query = s.createQuery(cq);
result = new HashSet<BallotManifestInfo>(query.getResultList());
} catch (final PersistenceException e) {
Copy link
Member

Choose a reason for hiding this comment

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

I think e is still final.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ope, I missed it. Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Persistence.beginTransaction();

Copy link
Member

Choose a reason for hiding this comment

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

@michelleblom pointed out when I set all this up explicitly that there's probably a much slicker way to do it - possibly setting all these values in test/resources/test.properties.

This worked great in the raire-service: https://github.com/DemocracyDevelopers/raire-service/tree/main/src/test/resources
but we were not keen to fiddle with colorado-rla in case we messed up the other tests. But now that you've got the other tests working, possibly you/we can avoid doing all this postgresql container config explicitly every time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah thanks, that's a great idea.

Base automatically changed from umbernhard-patch-1 to main June 21, 2024 03:41
@umbernhard umbernhard force-pushed the queries-tests branch 2 times, most recently from 3feb685 to f787fb0 Compare June 22, 2024 20:53
@umbernhard umbernhard marked this pull request as ready for review June 24, 2024 01:04
@umbernhard
Copy link
Collaborator Author

I'm marking this as ready for review, I think I was taking a wrongheaded approach in bundling all these changes in 1 PR, going forward I will break each new/modified test file into its own PR to make reviews less of a nightmare. @vteague @michelleblom I can do that with this one too if that's easier for you than going through this one.

@umbernhard umbernhard requested a review from vteague June 24, 2024 01:09
Copy link
Member

@vteague vteague left a comment

Choose a reason for hiding this comment

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

This looks great, thanks.

@vteague vteague merged commit 97fe022 into main Jun 30, 2024
1 check passed
@vteague vteague deleted the queries-tests branch June 30, 2024 11:40
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