Don't accidentally share a named semaphore between test processes
WpfSharedTestData had two static members: Instance and TestSerializationGateName. TestSerializationGateName is the name of a system-wide Semaphore that was used to execute WpfFacts one at time. The intent is this was a GUID so it wouldn't actually be shared. Unfortunately, the Instance member is initialized first; and the non-static Semaphore field is initialized with the still uninitialized TestSerializationGateName. This means our Semaphore would always be named with a GUID of all-zeros, causing us to share the semaphore between all running xUnit processes. This was terribly bad for two reasons: 1. It kills test performance. We run tests in parallel in separate processes to ensure isolation, but this sharing of the semaphore meant that all of those processes are only running one test at a time, defeating all running of tests in parallel. 2. If one test process crashes, the Semaphore is never freed, meaning all your other test processes will deadlock and never complete. It's unclear why this code is using a Semaphore, but since we have no need to share the Semaphore between processes, we can use a SemaphoreSlim. This also has the added benefit of properly supporting a WaitAsync that isn't implemented by launching off a Thread just to wait for the system semaphore.
Showing
想要评论请 注册 或 登录