emilsjolander / sprinkles

Sprinkles is a boiler-plate-reduction-library for dealing with databases in android applications
Apache License 2.0
772 stars 84 forks source link

[Question] In a testcase, is there any way to wait for all async operations to be finished? #73

Closed jordi-chacon closed 10 years ago

jordi-chacon commented 10 years ago

Hi!

I am writing a few tests for code that does business logic and triggers asynchronous db operations through sprinkles. My tests are basically failing when they expect certain data to be present in db, but the data is missing due to the async write not being completed yet. Therefore, for testing purposes, it seems that I need a way to wait for the async jobs to be finished before I do my assertions.

I have taken a quick look at Sprinkles but there doesn't seem to be a waiting mechanism, is that correct? Does Android provide a generic way to wait for all ongoing AsyncTasks to be completed? Otherwise, any tips on how to tackle this problem?

Thanks!

emilsjolander commented 10 years ago

You closed this issue, did you solve the problem ? :)

jordi-chacon commented 10 years ago

Yes, I did a workaround. I built a mechanism, just for testing purposes, which is basically a queue of all the asynchronous db operations that are ongoing at any time. From within the testcase, I wait for that queue to be empty before doing any assertions. That works fine and solved my problem!