mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
It is possible that the rest of the platforms are relying in some not clearly documented behaviour that the stdout is flushed before stderr can be used, or something similar. Windows didn't seem to like that, and was sometimes outputting the stderr messages interlaced with the stdout messages (specially in the Azure testing for VS2017). The initial solution was adding -DAG to some CHECK lines, but that doesn't cover all the possibilities, and wasn't enabled for all the checks. I tried to fix it in several ways, but none of them were perfect, and many of them were deadlocking. There's a fundamental difference between others and Windows and that is that for others stdout seems to have a little bit of an edge in being treated first. I tried to get the Windows code closer to that idea, but I have no luck. Some of the approaches were using the main thread to read from the threads reading stdout and stderr; using only the main thread and IOCP on the pipes reading from the child process; and flushing after every output to stdout. None of them were perfect. The final solution is a hack, but it seems to not fail when I run the test repeatedly in my machine, while other approaches were failing at least once before I discarded them. The solution is including a small sleep (1 millisecond) in the Windows code. This should yield the execution time slice to other thread/process, which seems to do the trick and keep the stdout before the stderr. Hopefully this fixes the errors in Azure, and doesn't affect the rest of the testing machines. Being a really small sleep also should not affect the duration of the test itself.