-
Notifications
You must be signed in to change notification settings - Fork 426
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
AC-1092: Add Tests for Observation Repository #1010
AC-1092: Add Tests for Observation Repository #1010
Conversation
getObservationByUuid(observationResource.uuid!!).subscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe( | ||
{ observation -> | ||
observationList.add(observation) | ||
}, | ||
{ error -> | ||
Log.e("Observation Repository", "Error: ${error.message}") | ||
}, | ||
{ | ||
Log.d("Observation Repository", "Observable completed") | ||
} | ||
) | ||
val observation = getObservationByUuid(observationResource.uuid!!) | ||
observationList.add(observation.execute()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing this subscriber and observer???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rishabh-997 I was the one who added this code but when unit tests were failing I noticed this was a bug. I replaced it with "execute()" method which returns the immediate result of observable available.
"fun Observable.execute(): T = this.single().toBlocking().first()"
Like this I did many refactoring in my earlier written code.
Regardless the api call is still kept as an observable so that implementers of SDK can implement it in that pattern if wanted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we are blocking the thread till the execution is completed instead of handling in backgraound and wait for results?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RestApi function gives the result immediately. And the result won't emit any addition to the observale too, since there are no triggers to the restApi function except for once in this ObservationRepository function.
I guess the restApi functions were kept to return observales since It's a good practice to maintain consistency in the codebase, if the majority of codebase uses reactive programming, returning an Observable or a Flow from Retrofit API functions would align well with the overall architecture of the SDK.
So here we are just fetching the immediate result, instead of waiting for more results because there are absolutely zero changes to the result after the initial execution. So, It won't be any worth for the thread to keep waiting.
Description of what I changed
Issue I worked on
JIRA Issue: https://issues.openmrs.org/browse/AC-1092
Checklist: I completed these to help reviewers :)
(the number above, next to the 'Commits' tab is 1).
existing code that was well tested you do not have to add tests)