rahul7386 / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

Thread Safety of ActivityUtils #586

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
ActivityUtils doesn't lock its ActivityMonitor before calling 
ActivityMonitor#getLastActivity.

Looking at the ActivityMonitor source you can see that mLastActivity is guarded 
by a lock everywhere except for ActivityMonitor#getLastActivity. Thus, 
ActivityUtils should lock on its ActivityMonitor before calling 
ActivityMonitor#getLastActivity in activitySyncTimerTask in 
ActivityUtils#setupActivityStackListener.

I can't make a reproducible test case for this, but I see symptoms where I 
Solo#waitForActivity fails. I can see that my emulator has moved to the 
activity, but calls to Solo#getCurrentActivity return the previous activity. 
This could be the cause.

Original issue reported on code.google.com by heath.bo...@gmail.com on 6 Mar 2014 at 4:31

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. We could explore if waitForActivity() can be used 
successfully instead of getLastActivity. 

Original comment by renasr...@gmail.com on 6 Mar 2014 at 7:47

GoogleCodeExporter commented 9 years ago
This change doesn't seem to work correctly for me. I find that when I use

      Solo.waitForActivity(MyActivity.class)

it's frequently failing when MyActivity is clearly the current Activity. The 
issue seems to be that waitForActivity() is being triggered by Activities that 
aren't at the top of the back stack, which results in the 
ActivityUtils.activityStack being incorrect.

I'd have thought this would have caused general problems, unless there's 
something odd that I'm doing to trigger the problem.

Original comment by jonathan...@googlemail.com on 12 Mar 2014 at 4:19

GoogleCodeExporter commented 9 years ago
I've figured out the 'something odd': I had the Developer options -> Don't keep 
activities set on my device, and this seems to completely break the behaviour, 
not only on 5.0.1 but on earlier versions too.

Original comment by jonathan...@googlemail.com on 13 Mar 2014 at 12:14

GoogleCodeExporter commented 9 years ago
I have sent you the 5.1 RC. Please let me know how the activity handling is 
working for you. 

Original comment by renasr...@gmail.com on 13 Mar 2014 at 12:17

GoogleCodeExporter commented 9 years ago
Thanks Renas that version you sent works well for me as long as I don't check 
the "Don't keep activities" option, whereas 5.0.1 seems to be unreliable even 
with that switched off.

I think some of my tests may need to be made more robust in terms of waiting 
for Activies to be fully loaded & set up in the "Don't keep activities" case, 
but I do see some failures right at the start when I'm waiting for my initial 
post-lanuch Activity to display, and it's clearly there.

Original comment by jonathan...@googlemail.com on 14 Mar 2014 at 11:29

GoogleCodeExporter commented 9 years ago
I'm glad to hear that its working better for you. 5.1 will be released on 
Monday. Thanks for helping us test it. 

Original comment by renasr...@gmail.com on 14 Mar 2014 at 11:44

GoogleCodeExporter commented 9 years ago
Thanks again for reporting this. This has been fixed in 5.1. 

Original comment by renasr...@gmail.com on 17 Mar 2014 at 6:10