Fix unreliability in async_read.exe test
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Tue, 1 Mar 2016 05:09:51 +0000 (06:09 +0100)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Tue, 1 Mar 2016 05:15:25 +0000 (06:15 +0100)
commit016efd505fc0abac40764cc66f6082def437d8b5
treed788323efdea61fbbfe3fb6d2b41ff6d8ebd6404
parent9d596e5b2b8888d250c1bd158b056406d96cb641
Fix unreliability in async_read.exe test

It failed on Jenkins today (https://jenkins.mono-project.com/job/test-mono-mainline/label=debian-amd64/3611/parsed_console/log_content.html#WARNING1)
and I could repro it after running the test in a loop.

While looking at the test, the "sum -= buf [0]" seemed suspicious to me. The final callback invocation after the last byte was read results
in buf [0] being 0 most of the time (because no bytes were read). However, due to the async nature of the test that final callback might happen
before another callback and buf then has a value, resulting in a wrong checksum if that value is substracted.

The fix is to remove the substraction. I have no idea why it was done in the first place, but it's been there since the test was added in 2003...

While at it, I've added another check for the number of bytes read and used proper Interlocked.* operations to ensure atomicity.
mono/tests/async_read.cs