Added test and fixed bug in future when onSuccess was called after the future was completed.