What are some strategies to unit test a scheduler?

后端 未结 5 1723
温柔的废话
温柔的废话 2020-12-15 23:05

This post started out as \"What are some common patterns in unit testing multi-threaded code ?\", but I found some other discussions on SO that generally agreed that \"It is

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 23:43

    A couple of ways to test concurrent code.

    • run the same code many times under load, some bugs appear only occasionally, but can show up consistently if performed repeatedly.
    • Store the results of different threads/jobs in a collection such as a BlockingQueue. This will allow you to check the results in the current thread and finish in a timely manner (without ugly arbitrary sleep statements)

    If you are finding testing concurrency difficult consider refactoring your objects/components to make them easier to test.

提交回复
热议问题