def test_ack(self):
        original_crash_id = create_new_ooid()

        manager = get_config_manager()
        with manager.context() as config:
            pubsub_helper = PubSubHelper(config)

            with pubsub_helper as pubsub:
                # Publish crash id to the queue
                pubsub.publish('standard', original_crash_id)

                crash_queue = PubSubCrashQueue(config)
                new_crashes = list(crash_queue.new_crashes())

                # Assert original_crash_id is in new_crashes
                crash_ids = [item[0][0] for item in new_crashes]
                assert crash_ids == [original_crash_id]

                # Now call it again; note that we haven't acked the crash_ids
                # nor have the leases expired
                second_new_crashes = list(crash_queue.new_crashes())
                assert second_new_crashes == []

                # Now ack the crash_id and we don't get it again
                for args, kwargs in new_crashes:
                    kwargs['finished_func']()

                # Wait beyond the ack deadline in the grossest way possible
                time.sleep(ACK_DEADLINE + 1)

                # Now call it again and make sure we get nothing back
                new_crashes = list(crash_queue.new_crashes())
                assert new_crashes == []
    def test_iter(self):
        manager = get_config_manager()
        with manager.context() as config:
            pubsub_helper = PubSubHelper(config)

            with pubsub_helper as pubsub:
                standard_crash = create_new_ooid()
                pubsub.publish('standard', standard_crash)

                reprocessing_crash = create_new_ooid()
                pubsub.publish('reprocessing', reprocessing_crash)

                priority_crash = create_new_ooid()
                pubsub.publish('priority', priority_crash)

                crash_queue = PubSubCrashQueue(config)
                new_crashes = list(crash_queue.new_crashes())

        # Assert the shape of items in new_crashes
        for item in new_crashes:
            assert isinstance(item, tuple)
            assert isinstance(item[0], tuple)  # *args
            assert isinstance(item[1], dict)  # **kwargs
            assert list(item[1].keys()) == ['finished_func']

        # Assert new_crashes order is the correct order
        crash_ids = [item[0][0] for item in new_crashes]
        assert crash_ids == [
            priority_crash, standard_crash, reprocessing_crash
        ]
예제 #3
0
    def test_ack(self):
        original_crash_id = create_new_ooid()

        manager = get_config_manager()
        with manager.context() as config:
            pubsub_helper = PubSubHelper(config)

            with pubsub_helper as pubsub:
                # Publish crash id to the queue
                pubsub.publish('standard', original_crash_id)

                crash_queue = PubSubCrashQueue(config)
                new_crashes = list(crash_queue.new_crashes())

                # Assert original_crash_id is in new_crashes
                crash_ids = [item[0][0] for item in new_crashes]
                assert crash_ids == [original_crash_id]

                # Now call it again; note that we haven't acked the crash_ids
                # nor have the leases expired
                second_new_crashes = list(crash_queue.new_crashes())
                assert second_new_crashes == []

                # Now ack the crash_id and we don't get it again
                for args, kwargs in new_crashes:
                    kwargs['finished_func']()

                # Wait beyond the ack deadline in the grossest way possible
                time.sleep(ACK_DEADLINE + 1)

                # Now call it again and make sure we get nothing back
                new_crashes = list(crash_queue.new_crashes())
                assert new_crashes == []
예제 #4
0
    def test_iter(self):
        manager = get_config_manager()
        with manager.context() as config:
            pubsub_helper = PubSubHelper(config)

            with pubsub_helper as pubsub:
                standard_crash = create_new_ooid()
                pubsub.publish('standard', standard_crash)

                reprocessing_crash = create_new_ooid()
                pubsub.publish('reprocessing', reprocessing_crash)

                priority_crash = create_new_ooid()
                pubsub.publish('priority', priority_crash)

                crash_queue = PubSubCrashQueue(config)
                new_crashes = list(crash_queue.new_crashes())

        # Assert the shape of items in new_crashes
        for item in new_crashes:
            assert isinstance(item, tuple)
            assert isinstance(item[0], tuple)  # *args
            assert isinstance(item[1], dict)   # **kwargs
            assert list(item[1].keys()) == ['finished_func']

        # Assert new_crashes order is the correct order
        crash_ids = [item[0][0] for item in new_crashes]
        assert crash_ids == [priority_crash, standard_crash, reprocessing_crash]
예제 #5
0
    def test_PriorityJob(self):
        # This test runs against the Pub/Sub emulator, so undo the mock to let
        # that work.
        self.undo_implementation_mock(models.PriorityJob)

        config_manager = get_config_manager()
        with config_manager.context() as config:
            pubsub_helper = PubSubHelper(config)
            api = models.PriorityJob()

            with pubsub_helper as helper:
                api.post(crash_ids='some-crash-id')

                crash_ids = helper.get_crash_ids('priority')
                assert crash_ids == ['some-crash-id']
예제 #6
0
    def test_PriorityJob(self):
        # This test runs against the Pub/Sub emulator, so undo the mock to let
        # that work.
        self.undo_implementation_mock(models.PriorityJob)

        config_manager = get_config_manager()
        with config_manager.context() as config:
            pubsub_helper = PubSubHelper(config)
            api = models.PriorityJob()

            with pubsub_helper as helper:
                api.post(crash_ids='some-crash-id')

                crash_ids = helper.get_crash_ids('priority')
                assert crash_ids == ['some-crash-id']
예제 #7
0
    def test_Reprocessing(self):
        # This test runs against the Pub/Sub emulator, so undo the mock to let
        # that work.
        self.undo_implementation_mock(models.Reprocessing)

        config_manager = get_config_manager()
        with config_manager.context() as config:
            pubsub_helper = PubSubHelper(config)
            api = models.Reprocessing()

            with pubsub_helper as helper:
                api.post(crash_ids="some-crash-id")

                crash_ids = helper.get_crash_ids("reprocessing")
                assert crash_ids == ["some-crash-id"]
예제 #8
0
    def test_Reprocessing(self):
        # This test runs against the Pub/Sub emulator, so undo the mock to let
        # that work.
        self.undo_implementation_mock(models.Reprocessing)

        config_manager = get_config_manager()
        with config_manager.context() as config:
            pubsub_helper = PubSubHelper(config)
            api = models.Reprocessing()

            with pubsub_helper as helper:
                crash_id = create_new_ooid()
                api.post(crash_ids=crash_id)

                crash_ids = helper.get_crash_ids("reprocessing")
                assert crash_ids == [crash_id]

            # Now try an invalid crash id
            with pytest.raises(BadArgumentError):
                api.post(crash_ids="some-crash-id")