Unit Testing Concurrent Code

前端 未结 1 635
无人及你
无人及你 2020-12-10 19:55

My weekend project consists of writing a cross-platform concurrency primitives library (critical sections, read/write mutexes, interlocked integers, events, etc) and was won

相关标签:
1条回答
  • 2020-12-10 20:38

    Don't think about unit tests, think about the behaviour you want to specify. For example:

    Given_an_unlocked_lock
        It_should_be_possible_to_take_it
    Given_a_locked_lock
        It_should_not_be_possible_to_take_it_from_another_thread
        It_should_be_possible_take_it_from_the_same_thread
    Given_a_locked_lock_when_unlocked
        It_should_be_possible_to_take_it
    Given_a_locked_lock_when_owning_thread_terminates
        It_should_be_possible_to_take_it
    

    I think that will help you identify what to do. And yes probably you need a helper thread in your unit tests to make it happen. Maybe this example is helpful.

    0 讨论(0)
提交回复
热议问题