Esempio n. 1
0
    def test_receive_request_with_same_owner_should_do_nothing(
            self, fork: Fork, philosopher: Philosopher):
        fork._owner = philosopher

        fork.request(philosopher)

        assert fork._owner == philosopher
Esempio n. 2
0
    def test_receive_request_from_some_neighbor_with_dirty_state_should_clean_it_and_change_owner(  # noqa
            self, fork: Fork, philosopher: Philosopher):
        another_fork = Fork(1)
        another_philosopher = Philosopher(1, (fork, another_fork))

        fork._owner = another_philosopher

        fork.request(philosopher)

        assert fork.state == ForkState.CLEAN
        assert fork._owner == philosopher
Esempio n. 3
0
    def test_receive_request_from_some_neighbor_with_clean_state_should_wait_until_the_owner_is_done(  # noqa
            self, fork: Fork, philosopher: Philosopher):
        another_fork = Fork(1)
        another_philosopher = Philosopher(1, (fork, another_fork))

        fork.state = ForkState.CLEAN
        fork._owner = another_philosopher

        with mock.patch(
                'dining_philosophers.forks.Condition.wait') as mock_wait:
            fork.request(philosopher)

            assert mock_wait.called