Like many flakey tests, this issue is due to timing. The test is expecting a token to be canceled, and it is, but some of the assert statements need more time before they can pass. The patch adds some waitFor blocks to help with this. I ran the test 50 times and it passes every time now. Without the changes, it would fail pretty much every time for me.