planetarium / libplanet

Blockchain in C#/.NET for on-chain, decentralized gaming
https://docs.libplanet.io/
GNU Lesser General Public License v2.1
506 stars 142 forks source link

SwarmTest.Preload test fails intermittently #430

Closed moreal closed 5 years ago

moreal commented 5 years ago
[xUnit.net 00:01:39.88]     Libplanet.Tests.Net.SwarmTest.Preload [FAIL]
Failed   Libplanet.Tests.Net.SwarmTest.Preload
Error Message:
 Assert.Equal() Failure
Expected: PreloadState[] [BlockDownloadState { CurrentPhase = 1, ReceivedBlockCount = 1, ReceivedBlockHash = a3b637176b11885731c8a5f640887f57a36bc0219ea020f0236e91f1b16e194d, TotalBlockCount = 10 }, BlockDownloadState { CurrentPhase = 1, ReceivedBlockCount = 2, ReceivedBlockHash = adee549ad524e779f522667e17fe8da6c856b23a84af972e354da849eb961f00, TotalBlockCount = 10 }, BlockDownloadState { CurrentPhase = 1, ReceivedBlockCount = 3, ReceivedBlockHash = 19c8706ed043c9ae8304e62612df45ad06d873ea6b73b63e674e89ed8e283600, TotalBlockCount = 10 }, BlockDownloadState { CurrentPhase = 1, ReceivedBlockCount = 4, ReceivedBlockHash = 2ad0fbaad728fe4f91726b7c7ec599ba47e08734b265bf04ce2b17898fe92000, TotalBlockCount = 10 }, BlockDownloadState { CurrentPhase = 1, ReceivedBlockCount = 5, ReceivedBlockHash = 597bf783ddf06a3002634ed6303182f31f21c9a3ff6240f95ef7981d90061a00, TotalBlockCount = 10 }, ...]
Actual:   List<PreloadState> [BlockDownloadState { CurrentPhase = 1, ReceivedBlockCount = 1, ReceivedBlockHash = a3b637176b11885731c8a5f640887f57a36bc0219ea020f0236e91f1b16e194d, TotalBlockCount = 10 }, BlockDownloadState { CurrentPhase = 1, ReceivedBlockCount = 2, ReceivedBlockHash = adee549ad524e779f522667e17fe8da6c856b23a84af972e354da849eb961f00, TotalBlockCount = 10 }, BlockDownloadState { CurrentPhase = 1, ReceivedBlockCount = 3, ReceivedBlockHash = 19c8706ed043c9ae8304e62612df45ad06d873ea6b73b63e674e89ed8e283600, TotalBlockCount = 10 }, BlockDownloadState { CurrentPhase = 1, ReceivedBlockCount = 4, ReceivedBlockHash = 2ad0fbaad728fe4f91726b7c7ec599ba47e08734b265bf04ce2b17898fe92000, TotalBlockCount = 10 }, BlockDownloadState { CurrentPhase = 1, ReceivedBlockCount = 5, ReceivedBlockHash = 597bf783ddf06a3002634ed6303182f31f21c9a3ff6240f95ef7981d90061a00, TotalBlockCount = 10 }, ...]
moreal commented 5 years ago

The fail was occurred by ThreadPool.QueueUserWorkItem.

// expected
ActionExecutionState { CurrentPhase = 4, ExecutedBlockCount = 8, ExecutedBlockHash = 7e460070b002b8676f16dbee4b638027c639efc7def746b18ee971dd07861400, TotalBlockCount = 11 }, ActionExecutionState { CurrentPhase = 4, ExecutedBlockCount = 9, ExecutedBlockHash = f438f623ebb0d3ece603f2c380aa946dceeb97ebedac1fa244df12c6e42f0800, TotalBlockCount = 11 }, ActionExecutionState { CurrentPhase = 4, ExecutedBlockCount = 10, ExecutedBlockHash = 77b76146baf96433d6e81abb6e54dcb0975f91210348b257fdc332155c592100, TotalBlockCount = 11 },

// actual
ActionExecutionState { CurrentPhase = 4, ExecutedBlockCount = 9, ExecutedBlockHash = f438f623ebb0d3ece603f2c380aa946dceeb97ebedac1fa244df12c6e42f0800, TotalBlockCount = 11 }, ActionExecutionState { CurrentPhase = 4, ExecutedBlockCount = 8, ExecutedBlockHash = 7e460070b002b8676f16dbee4b638027c639efc7def746b18ee971dd07861400, TotalBlockCount = 11 }, ActionExecutionState { CurrentPhase = 4, ExecutedBlockCount = 10, ExecutedBlockHash = 77b76146baf96433d6e81abb6e54dcb0975f91210348b257fdc332155c592100, TotalBlockCount = 11 },

In implementation of Progress<T>.Report(), it uses ThreadPool.QueueUserWorkItem with handler we made, so we can't expect to get the states exactly sorted because of that.

Progress<T>.Report -> Progress<T>.OnReport -> SynchronizationContext.Post -> ThreadPool.QueueUserWorkItem