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

EA-141: Fixed randomly failing test #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HelioStrike
Copy link

The test AdtServiceComponentTest.test_getVisitsAndHasVisitDuring() failed randomly because of the line:

assertFalse(service.hasVisitDuring(patient, outpatientDepartment, stopDate, now));

where stopDate is some date from 2012. There was no test above this line which created a visit between the 2 dates, hence the test wasn't definitely failing. As the test patient was being fetched from the database, there's no telling if the patient doesn't have a visit between the specified date range(hasVisitDuring() internally fetches inactive visits too!), which caused the test to fail 'randomly'. I wasn't sure what I should be replacing the line with, so I simply removed it. Doing that fixes the issue.

@dkayiwa
Copy link
Member

dkayiwa commented Mar 2, 2019

The original author intentionally put that assertion. So just removing it is not the fix.

@HelioStrike
Copy link
Author

HelioStrike commented Mar 2, 2019

Got it. I'll start working on an actual fix.

@HelioStrike HelioStrike force-pushed the EA-141 branch 3 times, most recently from b05fd91 to a6d8039 Compare March 3, 2019 09:33
@HelioStrike
Copy link
Author

HelioStrike commented Mar 3, 2019

@dkayiwa I added 2 new methods to AdtService, namely getActiveVisits() and hasActiveVisitsDuring().
The line which was causing the test to fail:

assertFalse(service.hasVisitDuring(patient, outpatientDepartment, stopDate, now));

now becomes:

assertFalse(service.hasActiveVisitDuring(patient, outpatientDepartment, stopDate, now));

I also changed the line:

Date now = new Date(System.currentTimeMillis() - 60*1000);

to:

Date now = new Date(System.currentTimeMillis() - 60*1000);

, going back by a minute. I did this because I wasn't sure whether visits ending at 'now' would be considered active. I think going back by a second would work too, but during creation visits timings are precise up to a minute, so I went with that option. I tested the updated code by running mvn clean install around 10 times, but the test passes.

@dkayiwa
Copy link
Member

dkayiwa commented Mar 8, 2019

Do you have to add the new methods to fix the randomly failing test?

@HelioStrike
Copy link
Author

@dkayiwa I would assume so. I believe the test is trying to check that the number of active visits until the current point in time is 0. Since hasVisitsDuring() returns all visits, I think the new methods would serve the purpose better.

* during the specified datetime range
*
* @param patient
* @param location
Copy link
Member

Choose a reason for hiding this comment

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

Can you document these params?

@@ -300,6 +300,29 @@ VisitDomainWrapper createRetrospectiveVisit(Patient patient, Location location,
*/
boolean hasVisitDuring(Patient patient, Location location, Date startDatetime, Date stopDatetime);

/**
* Gets all visits for the patient at the visit location associated with the specified location
Copy link
Member

Choose a reason for hiding this comment

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

The description does not seem to communicate what is reflected by the method name.

@HelioStrike
Copy link
Author

@dkayiwa I've updated the comments. Please have another look.

* the specified location during the specified datetime range
*
* @param patient
* @param location
Copy link
Member

Choose a reason for hiding this comment

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

Can you document these params?

@dkayiwa
Copy link
Member

dkayiwa commented Mar 20, 2019

@HelioStrike are you still working on this?

@HelioStrike
Copy link
Author

HelioStrike commented Mar 21, 2019

@dkayiwa I think its ready and good to go. By documenting, do you mean sticking a little comment to the right of the @param lines. If so, I'm not sure if I should document the params, because none of the other functions in the file have documented params and it would look a little odd in the file.
Here's the hasVisitDuring() function (present before the changes):

    /**
     * Returns true/false whether or not the patient has any visits at the visit location associated with
     * the specified location during the specified datetime range
     *
     * @param patient
     * @param location
     * @param startDatetime
     * @param stopDatetime
     * @return
     */
    boolean hasVisitDuring(Patient patient, Location location, Date startDatetime, Date stopDatetime);

And here's the new function, hasActiveVisitDuring():

    /**
     * Returns true/false whether or not the patient has any active visits at the visit location associated with
     * the specified location during the specified datetime range
     *
     * @param patient
     * @param location
     * @param startDatetime
     * @param stopDatetime
     * @return
     */
    boolean hasActiveVisitDuring(Patient patient, Location location, Date startDatetime, Date stopDatetime);

All I did was change the description a little to match what the new function was doing. Should I go ahead and put a comment beside each param?

haripriya999 pushed a commit to haripriya999/openmrs-module-emrapi that referenced this pull request May 29, 2019
@ibacher ibacher force-pushed the master branch 2 times, most recently from 2636a11 to 2b434a3 Compare August 5, 2021 20:32
@dkayiwa
Copy link
Member

dkayiwa commented Jan 9, 2022

Should I go ahead and put a comment beside each param?

Yes go ahead.

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