Пример #1
0
    def test_queue_fetches(self, mock_queue_fetch):
        workflow = Workflow.objects.create()
        tab = workflow.tabs.create(position=0)

        # step1 does not auto-update
        step1 = tab.steps.create(order=0,
                                 slug="step-1",
                                 auto_update_data=False)

        # step2 is ready to update
        step2 = tab.steps.create(
            order=1,
            slug="step-2",
            auto_update_data=True,
            last_update_check=parser.parse("1999-08-28T14:24"),
            next_update=parser.parse("1999-08-28T14:34"),
            update_interval=600,
        )

        # step3 has a few more minutes before it should update
        step3 = tab.steps.create(
            order=2,
            slug="step-3",
            auto_update_data=True,
            last_update_check=parser.parse("1999-08-28T14:20"),
            next_update=parser.parse("1999-08-28T14:40"),
            update_interval=1200,
        )

        mock_queue_fetch.return_value = future_none

        with freeze_time("1999-08-28T14:35"):
            # eat log messages
            with self.assertLogs(autoupdate.__name__, logging.INFO):
                self.run_with_async_db(
                    autoupdate.queue_fetches(SuccessfulRenderLock()))

        self.assertEqual(mock_queue_fetch.call_count, 1)
        mock_queue_fetch.assert_called_with(workflow.id, step2.id)

        step2.refresh_from_db()
        self.assertTrue(step2.is_busy)

        # Second call shouldn't fetch again, because it's busy
        with freeze_time("1999-08-28T14:36"):
            self.run_with_async_db(
                autoupdate.queue_fetches(SuccessfulRenderLock()))

        self.assertEqual(mock_queue_fetch.call_count, 1)
Пример #2
0
    def test_queue_fetches(self, mock_queue_fetch):
        workflow = Workflow.objects.create()
        tab = workflow.tabs.create(position=0)

        # wfm1 does not auto-update
        wfm1 = tab.wf_modules.create(order=0,
                                     slug="step-1",
                                     auto_update_data=False)

        # wfm2 is ready to update
        wfm2 = tab.wf_modules.create(
            order=1,
            slug="step-2",
            auto_update_data=True,
            last_update_check=parser.parse("Aug 28 1999 2:24PM UTC"),
            next_update=parser.parse("Aug 28 1999 2:34PM UTC"),
            update_interval=600,
        )

        # wfm3 has a few more minutes before it should update
        wfm3 = tab.wf_modules.create(
            order=2,
            slug="step-3",
            auto_update_data=True,
            last_update_check=parser.parse("Aug 28 1999 2:20PM UTC"),
            next_update=parser.parse("Aug 28 1999 2:40PM UTC"),
            update_interval=1200,
        )

        mock_queue_fetch.return_value = future_none

        # eat log messages
        with self.assertLogs(autoupdate.__name__, logging.INFO):
            self.run_with_async_db(
                autoupdate.queue_fetches(SuccessfulRenderLock()))

        self.assertEqual(mock_queue_fetch.call_count, 1)
        mock_queue_fetch.assert_called_with(workflow.id, wfm2.id)

        wfm2.refresh_from_db()
        self.assertTrue(wfm2.is_busy)

        # Second call shouldn't fetch again, because it's busy
        self.run_with_async_db(autoupdate.queue_fetches(
            SuccessfulRenderLock()))

        self.assertEqual(mock_queue_fetch.call_count, 1)