Exemple #1
0
def test_deferred_action_times_out(sql_alchemy_fixture, deferred_action_fixture):
    """If all its Requirements are not fulfilled before its deadline has been reached, a DeferredAction executes its deadline action; then, it and its Requirements are deleted"""

    fixture = deferred_action_fixture
    with sql_alchemy_fixture.persistent_test_classes(fixture.MyDeferredAction, fixture.SomeObject):
        requirements = [Requirement(), Requirement(), Requirement()]
        deferred_action = fixture.MyDeferredAction(fixture.one_object, requirements=requirements, deadline=fixture.future_time)
        Session.add(deferred_action)
        Session.flush()

        assert deferred_action.deadline == fixture.future_time
        ReahlEgg.do_daily_maintenance_for_egg('reahl-domain')
        assert not fixture.one_object.deadline_flag
        assert not fixture.another_object.deadline_flag

        assert Session.query(Requirement).count() == 3
        assert Session.query(DeferredAction).count() == 1

        deferred_action.deadline = fixture.past_time
        ReahlEgg.do_daily_maintenance_for_egg('reahl-domain')
        assert fixture.one_object.deadline_flag
        assert not fixture.another_object.deadline_flag

        assert Session.query(Requirement).count() == 0
        assert Session.query(DeferredAction).count() == 0
Exemple #2
0
def test_deferred_action_completes_with_shared_requirements(
        sql_alchemy_fixture, deferred_action_fixture):
    """A requirement could be linked to many DeferredActions, in which case it will notify all on success"""

    fixture = deferred_action_fixture
    with sql_alchemy_fixture.persistent_test_classes(fixture.MyDeferredAction,
                                                     fixture.SomeObject):
        requirements1 = [Requirement()]
        requirements2 = [Requirement(), Requirement()]
        deferred_action1 = fixture.MyDeferredAction(
            fixture.one_object,
            requirements=requirements2,
            deadline=fixture.future_time)
        Session.add(deferred_action1)
        deferred_action2 = fixture.MyDeferredAction(
            fixture.another_object,
            requirements=requirements1 + requirements2,
            deadline=fixture.future_time)

        Session.add(deferred_action2)
        Session.flush()
        # The requirements are linked back to the correct DeferredActions
        for requirement in requirements2:
            assert set(requirement.deferred_actions) == {
                deferred_action1, deferred_action2
            }

        for requirement in requirements1:
            assert set(requirement.deferred_actions) == {deferred_action2}

        # If all of one DeferredAction's Requirements are fulfilled, ones also linked to another DeferrredAction
        # are not deleted just yet
        for requirement in requirements2:
            requirement.set_fulfilled()
        assert fixture.one_object.done_flag
        assert not fixture.another_object.done_flag

        for requirement in requirements1 + requirements2:
            assert set(requirement.deferred_actions) == {deferred_action2}
        assert Session.query(Requirement).count() == 3
        assert Session.query(DeferredAction).count() == 1

        # But as soon as all Requirements of the last DeferredAction are fulfilled, the last Requirements
        # are deleted as usual
        for requirement in requirements1:
            requirement.set_fulfilled()
        assert fixture.one_object.done_flag
        assert fixture.another_object.done_flag

        assert Session.query(Requirement).count() == 0
        assert Session.query(DeferredAction).count() == 0
Exemple #3
0
    def deferred_action_completes(self, fixture):
        """A DeferredAction will execute its primary action once all its Requirements are fulfilled; then, it and its Requirements are deleted."""
        with fixture.persistent_test_classes(fixture.MyDeferredAction, fixture.SomeObject):
            requirements = [Requirement(), Requirement(), Requirement()]
            deferred_action = fixture.MyDeferredAction(fixture.one_object, requirements=requirements, deadline=fixture.future_time)
            Session.add(deferred_action)
            Session.flush()
            for requirement in requirements:
                requirement.set_fulfilled()
            vassert( fixture.one_object.done_flag )
            vassert( not fixture.another_object.done_flag )

            vassert( Session.query(Requirement).count() == 0 )
            vassert( Session.query(DeferredAction).count() == 0 )
Exemple #4
0
def test_deferred_action_times_out_with_shared_requirements(
        sql_alchemy_fixture, deferred_action_fixture):
    """If a DeferredAction times out, it will not nuke Requirements shared with another DeferredAction."""

    fixture = deferred_action_fixture
    with sql_alchemy_fixture.persistent_test_classes(fixture.MyDeferredAction,
                                                     fixture.SomeObject):
        requirements1 = [Requirement()]
        requirements2 = [Requirement(), Requirement()]
        deferred_action1 = fixture.MyDeferredAction(
            fixture.one_object,
            requirements=requirements2,
            deadline=fixture.future_time)
        Session.add(deferred_action1)
        deferred_action2 = fixture.MyDeferredAction(
            fixture.another_object,
            requirements=requirements1 + requirements2,
            deadline=fixture.future_time)

        Session.add(deferred_action2)
        Session.flush()

        # If one DeferredAction times out, the remaining one and its Requirements are left intact
        deferred_action1.deadline = fixture.past_time

        ReahlEgg.do_daily_maintenance_for_egg('reahl-domain')
        assert fixture.one_object.deadline_flag
        assert not fixture.another_object.deadline_flag

        assert Session.query(Requirement).count() == 3
        assert Session.query(DeferredAction).count() == 1

        for requirement in requirements1 + requirements2:
            assert set(requirement.deferred_actions) == {deferred_action2}

        # When no more DeferredActions are held onto by Requirements, those Requirements are deleted
        deferred_action2.deadline = fixture.past_time
        ReahlEgg.do_daily_maintenance_for_egg('reahl-domain')

        assert fixture.one_object.deadline_flag
        assert fixture.another_object.deadline_flag

        assert Session.query(Requirement).count() == 0
        assert Session.query(DeferredAction).count() == 0