Пример #1
0
 def test_run_nested(self, fake_time):
     c = time.Clock()
     with c.run("outer"):
         fake_time.time += 3
         with c.run("inner"):
             fake_time.time += 4
     assert str(c) == "<Clock(outer=7.00, inner=4.00)>"
Пример #2
0
 def test_run_nested(self):
     c = time.Clock()
     with c.run("outer"):
         time.monotonic_time.time += 3
         with c.run("inner"):
             time.monotonic_time.time += 4
     self.assertEqual(str(c), "<Clock(outer=7.00, inner=4.00)>")
Пример #3
0
 def test_run_stopped(self):
     c = time.Clock()
     with c.run("stopped"):
         pass
     with pytest.raises(RuntimeError):
         with c.run("stopped"):
             pass
Пример #4
0
 def test_running(self, fake_time):
     c = time.Clock()
     c.start("foo")
     fake_time.time += 3
     c.start("bar")
     fake_time.time += 4
     c.stop("foo")
     assert str(c) == "<Clock(foo=7.00, bar=4.00*)>"
Пример #5
0
 def test_running(self):
     c = time.Clock()
     c.start("foo")
     time.monotonic_time.time += 3
     c.start("bar")
     time.monotonic_time.time += 4
     c.stop("foo")
     self.assertEqual(str(c), "<Clock(foo=7.00, bar=4.00*)>")
Пример #6
0
 def test_start_and_stop(self, fake_time):
     c = time.Clock()
     c.start("total")
     c.start("step1")
     fake_time.time += 3
     c.stop("step1")
     c.start("step2")
     fake_time.time += 4
     c.stop("step2")
     c.stop("total")
     assert str(c) == "<Clock(total=7.00, step1=3.00, step2=4.00)>"
Пример #7
0
 def test_start_and_stop(self):
     c = time.Clock()
     c.start("total")
     c.start("step1")
     time.monotonic_time.time += 3
     c.stop("step1")
     c.start("step2")
     time.monotonic_time.time += 4
     c.stop("step2")
     c.stop("total")
     self.assertEqual(str(c), "<Clock(total=7.00, step1=3.00, step2=4.00)>")
Пример #8
0
    def extend_volume(self,
                      vmDrive,
                      volumeID,
                      curSize,
                      capacity,
                      callback=None):
        """
        Extend drive volume and its replica volume during replication.

        Must be called only when the drive or its replica are chunked.

        If callback is specified, it will be invoked when the extend operation
        completes. If extension fails, the callback is called with an exception
        object. The callback signature is:

            def callback(error=None):

        """
        newSize = vmDrive.getNextVolumeSize(curSize, capacity)

        # If drive is replicated to a block device, we extend first the
        # replica, and handle drive later in _extend_replica_completed.

        # Used to measure the total extend time for the drive and the replica.
        # Note that the volume is extended after the replica is extended, so
        # the total extend time includes the time to extend the replica.
        clock = time.Clock()

        # If we received a block threshold event for this drive, include
        # the time since we received the event in the total time.
        # Otherwise measure only the time to extend the volume.
        if vmDrive.exceeded_time:
            clock.start("total", start_time=vmDrive.exceeded_time)
            clock.start("wait", start_time=vmDrive.exceeded_time)
            clock.stop("wait")
        else:
            clock.start("total")

        if vmDrive.replicaChunked:
            self._extend_replica(vmDrive, newSize, clock, callback=callback)
        else:
            self._extend_volume(vmDrive,
                                volumeID,
                                newSize,
                                clock,
                                callback=callback)
Пример #9
0
    def test_start_with_start_time(self, fake_time):
        # We received an event.
        event_time = fake_time.time

        # The event was handled after 5 seconds...
        fake_time.time += 5
        c = time.Clock()

        # The total time includes the wait time..
        c.start("total", start_time=event_time)

        # Measure the time we waited since the event was received.
        c.start("wait", start_time=event_time)
        c.stop("wait")

        # Measure processing time.
        c.start("process")
        fake_time.time += 2
        c.stop("process")

        c.stop("total")

        assert str(c) == "<Clock(total=7.00, wait=5.00, process=2.00)>"
Пример #10
0
 def test_run(self, fake_time):
     c = time.Clock()
     with c.run("foo"):
         fake_time.time += 3
     assert str(c) == "<Clock(foo=3.00)>"
Пример #11
0
 def test_no_timers(self):
     c = time.Clock()
     assert str(c) == "<Clock()>"
Пример #12
0
 def test_no_timers(self):
     c = time.Clock()
     self.assertEqual(str(c), "<Clock()>")
Пример #13
0
 def test_stop_missing_clock(self):
     c = time.Clock()
     self.assertRaises(RuntimeError, c.stop, "foo")
Пример #14
0
 def test_stop_stooped_clock(self):
     c = time.Clock()
     c.start("stopped")
     c.stop("stopped")
     with self.assertRaises(RuntimeError):
         c.stop("stopped")
Пример #15
0
 def test_run(self):
     c = time.Clock()
     with c.run("foo"):
         time.monotonic_time.time += 3
     self.assertEqual(str(c), "<Clock(foo=3.00)>")
Пример #16
0
 def test_stop_stooped_clock(self):
     c = time.Clock()
     c.start("stopped")
     c.stop("stopped")
     with pytest.raises(RuntimeError):
         c.stop("stopped")
Пример #17
0
 def test_stop_missing_clock(self):
     c = time.Clock()
     with pytest.raises(RuntimeError):
         c.stop("foo")
Пример #18
0
 def test_run_started(self):
     c = time.Clock()
     c.start("started")
     with pytest.raises(RuntimeError):
         with c.run("started"):
             pass