为什么 nextest 是每个测试进程 ꞏ 太阳雨

  • Why use process-per-test in Rust test runner cargo-nextest:

    • Rust ecosystem is large with millions of developers and billions of lines of code. A key challenge is coordination.
    • The process-per-test model serves as a focal point in game theory, like noon at Big Ben in London. It's a natural default that everyone can rely on without explicit coordination.
  • Benefits of separate processes:

    • Test authors and libraries don't need to coordinate global state usage. Many real-world use cases require per-test isolation, such as tests against graphical APIs or certain macOS frameworks.
    • Internal memory handling doesn't need to be coordinated across tests. Memory corruption in one test won't affect others.
    • Test runners don't need a custom protocol. They can rely on universal OS primitives like killing processes.
  • Costs of coordination:

    • In a shared-process model, effective and robust test management requires coordination between the test runner, a component within the test binary, and the test itself. This represents a lot of extra work in terms of technical and coordination aspects.
    • Tests might want to share in-memory state, but process-per-test makes it harder to achieve. There is also a performance cost on Windows and macOS.
  • Conclusion:

    • The process-per-test model has many technical benefits, and the biggest benefit is in the lack of coordination. It acts as a default agreement among participants.
    • We're excited to see developments in this space and consider opt-ins for newer patterns.
  • Appendix: thread cancellation is hard:

    • Terminating threads is more difficult than terminating processes. Functions like TerminateThread and pthread_cancel are dangerous and can lead to undefined behavior of synchronization primitives.
    • The only reliable way to cancel synchronous Rust code is with cooperation from the test itself. With async Rust, cancellation is somewhat easier but Tokio mutexes are also not marked poisoned on task or future cancellation.
    • These examples show how focal points manifest and perpetuate in different contexts.
阅读 7
0 条评论