-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[windows][test] Ensure the ordering of stdout and stderr messages. #26317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[windows][test] Ensure the ordering of stdout and stderr messages. #26317
Conversation
@swift-ci please test Windows platform |
@swift-ci please smoke test |
Sigh. It was expected. The other test that's flaky in Windows. @swift-ci please test Windows platform |
@swift-ci please test Windows platform |
Funny thing. Seems that windows-2019-2 machine in CI didn't refreshed the environment variables and was never going to pass that test. @swift-ci please test Windows platform |
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.
ce3cc81
to
8bea502
Compare
@swift-ci please test Windows platform |
@swift-ci please smoke test |
@compnerd: do we still want this? It will solve one of the problems in https://dev.azure.com/compnerd/windows-swift/_build/results?buildId=5744&view=results |
This is horrible, but, if it makes the 2017 tests reliable, lets do it. |
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.