예제 #1
0
    def test_get_block(self, sleep):
        x = buckets.TaskBucket(task_registry=self.registry)
        x.not_empty = Mock()
        get = x._get = Mock()
        calls = [0]
        remaining = [0]

        def effect():
            try:
                if not calls[0]:
                    raise Empty()
                rem = remaining[0]
                remaining[0] = 0
                return rem, Mock()
            finally:
                calls[0] += 1

        get.side_effect = effect

        with mock_context(Mock()) as context:
            x.not_empty = context
            x.wait = Mock()
            x.get(block=True)

            calls[0] = 0
            remaining[0] = 1
            x.get(block=True)
예제 #2
0
    def test_get_block(self, sleep):
        x = buckets.TaskBucket(task_registry=self.registry)
        x.not_empty = Mock()
        get = x._get = Mock()
        calls = [0]
        remaining = [0]

        def effect():
            try:
                if not calls[0]:
                    raise Empty()
                rem = remaining[0]
                remaining[0] = 0
                return rem, Mock()
            finally:
                calls[0] += 1
        get.side_effect = effect

        with mock_context(Mock()) as context:
            x.not_empty = context
            x.wait = Mock()
            x.get(block=True)

            calls[0] = 0
            remaining[0] = 1
            x.get(block=True)
예제 #3
0
    def test_get_block(self, sleep):
        x = buckets.TaskBucket(task_registry=self.registry)
        x.not_empty = Mock()
        get = x._get = Mock()
        remaining = [0]

        def effect():
            if get.call_count == 1:
                raise Empty()
            rem = remaining[0]
            remaining[0] = 0
            return rem, Mock()
        get.side_effect = effect

        with mock_context(Mock()) as context:
            x.not_empty = context
            x.wait = Mock()
            x.get(block=True)

            get.reset()
            remaining[0] = 1
            x.get(block=True)
예제 #4
0
    def test_get_block(self, sleep):
        x = buckets.TaskBucket(task_registry=self.registry)
        x.not_empty = Mock()
        get = x._get = Mock()
        remaining = [0]

        def effect():
            if get.call_count == 1:
                raise Empty()
            rem = remaining[0]
            remaining[0] = 0
            return rem, Mock()
        get.side_effect = effect

        with mock_context(Mock()) as context:
            x.not_empty = context
            x.wait = Mock()
            x.get(block=True)

            get.reset()
            remaining[0] = 1
            x.get(block=True)