Fixed a race condition in the actual test, causing it to fail occasionally. Also added more documentation to the test, so it's easier to read and understand what's going on.