Rajesh noticed that
MDL-30157 was failing randomly, it is a race condition, get_enrolled_sql is checking (resuming) ue.timestart < time() instead of <=. I'm not sure why this is like this, but it might be intentional. I'm opening this issue to look at it and solving it if it should be fixed.
The dirty hack we introduced in
MDL-30157 last commit could be removed after this.
Some other cases to review: