Ejemplo n.º 1
0
 def test_advance_time_delta(self):
     timeutils.set_time_override(self.one_minute_before)
     timeutils.advance_time_delta(datetime.timedelta(seconds=60))
     self.assertEqual(timeutils.utcnow(), self.skynet_self_aware_time)
    def test_message_counter(self):
        queue_name = self.queue_name
        iterations = 10

        seed_marker1 = self.queue_controller._get_counter(queue_name,
                                                          self.project)
        self.assertEqual(seed_marker1, 1, 'First marker is 1')

        for i in range(iterations):
            self.controller.post(queue_name, [{'ttl': 60}],
                                 'uuid', project=self.project)

            marker1 = self.queue_controller._get_counter(queue_name,
                                                         self.project)
            marker2 = self.queue_controller._get_counter(queue_name,
                                                         self.project)
            marker3 = self.queue_controller._get_counter(queue_name,
                                                         self.project)

            self.assertEqual(marker1, marker2)
            self.assertEqual(marker2, marker3)
            self.assertEqual(marker1, i + 2)

        new_value = self.queue_controller._inc_counter(queue_name,
                                                       self.project)
        self.assertIsNotNone(new_value)

        value_before = self.queue_controller._get_counter(queue_name,
                                                          project=self.project)
        new_value = self.queue_controller._inc_counter(queue_name,
                                                       project=self.project)
        self.assertIsNotNone(new_value)
        value_after = self.queue_controller._get_counter(queue_name,
                                                         project=self.project)
        self.assertEqual(value_after, value_before + 1)

        value_before = value_after
        new_value = self.queue_controller._inc_counter(queue_name,
                                                       project=self.project,
                                                       amount=7)
        value_after = self.queue_controller._get_counter(queue_name,
                                                         project=self.project)
        self.assertEqual(value_after, value_before + 7)
        self.assertEqual(value_after, new_value)

        reference_value = value_after

        unchanged = self.queue_controller._inc_counter(queue_name,
                                                       project=self.project,
                                                       window=10)
        self.assertIsNone(unchanged)

        timeutils.set_time_override()
        timeutils.advance_time_delta(datetime.timedelta(seconds=10))

        changed = self.queue_controller._inc_counter(queue_name,
                                                     project=self.project,
                                                     window=5)
        self.assertEqual(changed, reference_value + 1)

        timeutils.clear_time_override()
Ejemplo n.º 3
0
 def advance_time_delta(self, timedelta):
     """Advance overridden time using a datetime.timedelta."""
     timeutils.advance_time_delta(timedelta)
Ejemplo n.º 4
0
    def test_message_counter(self):
        queue_name = self.queue_name
        iterations = 10

        m = mock.MagicMock(controllers.QueueController)
        self.controller._queue_ctrl = m
        del self.controller._queue_ctrl._get_counter
        del self.controller._queue_ctrl._inc_counter

        seed_marker1 = self.controller._get_counter(queue_name,
                                                    self.project)
        self.assertEqual(0, seed_marker1, 'First marker is 0')

        for i in range(iterations):
            self.controller.post(queue_name, [{'ttl': 60}],
                                 'uuid', project=self.project)

            marker1 = self.controller._get_counter(queue_name,
                                                   self.project)
            marker2 = self.controller._get_counter(queue_name,
                                                   self.project)
            marker3 = self.controller._get_counter(queue_name,
                                                   self.project)

            self.assertEqual(marker1, marker2)
            self.assertEqual(marker2, marker3)
            self.assertEqual(i + 1, marker1)

        new_value = self.controller._inc_counter(queue_name,
                                                 self.project)
        self.assertIsNotNone(new_value)

        value_before = self.controller._get_counter(queue_name,
                                                    project=self.project)
        new_value = self.controller._inc_counter(queue_name,
                                                 project=self.project)
        self.assertIsNotNone(new_value)
        value_after = self.controller._get_counter(queue_name,
                                                   project=self.project)
        self.assertEqual(value_before + 1, value_after)

        value_before = value_after
        new_value = self.controller._inc_counter(queue_name,
                                                 project=self.project,
                                                 amount=7)
        value_after = self.controller._get_counter(queue_name,
                                                   project=self.project)
        self.assertEqual(value_before + 7, value_after)
        self.assertEqual(new_value, value_after)

        reference_value = value_after

        unchanged = self.controller._inc_counter(queue_name,
                                                 project=self.project,
                                                 window=10)
        self.assertIsNone(unchanged)

        timeutils.set_time_override()
        timeutils.advance_time_delta(datetime.timedelta(seconds=10))

        changed = self.controller._inc_counter(queue_name,
                                               project=self.project,
                                               window=5)
        self.assertEqual(reference_value + 1, changed)

        timeutils.clear_time_override()
Ejemplo n.º 5
0
 def advance_time_delta(self, timedelta):
     """Advance overridden time using a datetime.timedelta."""
     timeutils.advance_time_delta(timedelta)
Ejemplo n.º 6
0
 def test_advance_time_delta(self):
     timeutils.set_time_override(self.one_minute_before)
     timeutils.advance_time_delta(datetime.timedelta(seconds=60))
     self.assertEqual(timeutils.utcnow(), self.skynet_self_aware_time)
Ejemplo n.º 7
0
    def test_message_counter(self):
        queue_name = self.queue_name
        iterations = 10

        m = mock.MagicMock(controllers.QueueController)
        self.controller._queue_ctrl = m
        del self.controller._queue_ctrl._get_counter
        del self.controller._queue_ctrl._inc_counter

        seed_marker1 = self.controller._get_counter(queue_name,
                                                    self.project)
        self.assertEqual(0, seed_marker1, 'First marker is 0')

        for i in range(iterations):
            self.controller.post(queue_name, [{'ttl': 60}],
                                 'uuid', project=self.project)

            marker1 = self.controller._get_counter(queue_name,
                                                   self.project)
            marker2 = self.controller._get_counter(queue_name,
                                                   self.project)
            marker3 = self.controller._get_counter(queue_name,
                                                   self.project)

            self.assertEqual(marker1, marker2)
            self.assertEqual(marker2, marker3)
            self.assertEqual(i + 1, marker1)

        new_value = self.controller._inc_counter(queue_name,
                                                 self.project)
        self.assertIsNotNone(new_value)

        value_before = self.controller._get_counter(queue_name,
                                                    project=self.project)
        new_value = self.controller._inc_counter(queue_name,
                                                 project=self.project)
        self.assertIsNotNone(new_value)
        value_after = self.controller._get_counter(queue_name,
                                                   project=self.project)
        self.assertEqual(value_before + 1, value_after)

        value_before = value_after
        new_value = self.controller._inc_counter(queue_name,
                                                 project=self.project,
                                                 amount=7)
        value_after = self.controller._get_counter(queue_name,
                                                   project=self.project)
        self.assertEqual(value_before + 7, value_after)
        self.assertEqual(new_value, value_after)

        reference_value = value_after

        unchanged = self.controller._inc_counter(queue_name,
                                                 project=self.project,
                                                 window=10)
        self.assertIsNone(unchanged)

        timeutils.set_time_override()
        timeutils.advance_time_delta(datetime.timedelta(seconds=10))

        changed = self.controller._inc_counter(queue_name,
                                               project=self.project,
                                               window=5)
        self.assertEqual(reference_value + 1, changed)

        timeutils.clear_time_override()
Ejemplo n.º 8
0
    def test_message_counter(self):
        queue_name = self.queue_name
        iterations = 10

        seed_marker1 = self.queue_controller._get_counter(
            queue_name, self.project)
        self.assertEqual(seed_marker1, 1, 'First marker is 1')

        for i in range(iterations):
            self.controller.post(queue_name, [{
                'ttl': 60
            }],
                                 'uuid',
                                 project=self.project)

            marker1 = self.queue_controller._get_counter(
                queue_name, self.project)
            marker2 = self.queue_controller._get_counter(
                queue_name, self.project)
            marker3 = self.queue_controller._get_counter(
                queue_name, self.project)

            self.assertEqual(marker1, marker2)
            self.assertEqual(marker2, marker3)
            self.assertEqual(marker1, i + 2)

        new_value = self.queue_controller._inc_counter(queue_name,
                                                       self.project)
        self.assertIsNotNone(new_value)

        value_before = self.queue_controller._get_counter(queue_name,
                                                          project=self.project)
        new_value = self.queue_controller._inc_counter(queue_name,
                                                       project=self.project)
        self.assertIsNotNone(new_value)
        value_after = self.queue_controller._get_counter(queue_name,
                                                         project=self.project)
        self.assertEqual(value_after, value_before + 1)

        value_before = value_after
        new_value = self.queue_controller._inc_counter(queue_name,
                                                       project=self.project,
                                                       amount=7)
        value_after = self.queue_controller._get_counter(queue_name,
                                                         project=self.project)
        self.assertEqual(value_after, value_before + 7)
        self.assertEqual(value_after, new_value)

        reference_value = value_after

        unchanged = self.queue_controller._inc_counter(queue_name,
                                                       project=self.project,
                                                       window=10)
        self.assertIsNone(unchanged)

        timeutils.set_time_override()
        timeutils.advance_time_delta(datetime.timedelta(seconds=10))

        changed = self.queue_controller._inc_counter(queue_name,
                                                     project=self.project,
                                                     window=5)
        self.assertEqual(changed, reference_value + 1)

        timeutils.clear_time_override()