/opt/imh-python/lib/python3.9/site-packages/keystoneauth1/tests/unit
NameSizeModeActions
access/-0755rm
data/-0755rm
exceptions/-0755rm
extras/-0755rm
identity/-0755rm
loading/-0755rm
__pycache__/-0755rm
client_fixtures.py44750644editdlrm
k2k_fixtures.py53340644editdlrm
keystoneauth_fixtures.py23780644editdlrm
matchers.py31800644editdlrm
oidc_fixtures.py34990644editdlrm
test_betamax_fixture.py46280644editdlrm
test_betamax_hooks.py65930644editdlrm
test_betamax_serializer.py19730644editdlrm
test_discovery.py519610644editdlrm
test_fair_sempahore.py28930644editdlrm
test_fixtures.py137350644editdlrm
test_hacking_checks.py17990644editdlrm
test_http_basic.py18770644editdlrm
test_matchers.py34000644editdlrm
test_noauth.py17280644editdlrm
test_service_token.py46700644editdlrm
test_session.py801850644editdlrm
test_token_endpoint.py26320644editdlrm
test_utils.py8000644editdlrm
utils.py52340644editdlrm
__init__.py00644editdlrm
Edit: /opt/imh-python/lib/python3.9/site-packages/keystoneauth1/tests/unit/test_fair_sempahore.py (2893B)
# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import queue from threading import Thread from timeit import default_timer as timer from unittest import mock import testtools from keystoneauth1 import _fair_semaphore class SemaphoreTests(testtools.TestCase): def _thread_worker(self): while True: # get returns the Item, but we don't care about the value so we # purposely don't assign it to anything. self.q.get() with self.s: self.mock_payload.do_something() self.q.task_done() # Have 5 threads do 10 different "things" coordinated by the fair # semaphore. def _concurrency_core(self, concurrency, delay): self.s = _fair_semaphore.FairSemaphore(concurrency, delay) self.q = queue.Queue() for i in range(5): t = Thread(target=self._thread_worker) t.daemon = True t.start() for item in range(0, 10): self.q.put(item) self.q.join() def setUp(self): super().setUp() self.mock_payload = mock.Mock() # We should be waiting at least 0.1s between operations, so # the 10 operations must take at *least* 1 second def test_semaphore_no_concurrency(self): start = timer() self._concurrency_core(None, 0.1) end = timer() self.assertTrue((end - start) > 1.0) self.assertEqual(self.mock_payload.do_something.call_count, 10) def test_semaphore_single_concurrency(self): start = timer() self._concurrency_core(1, 0.1) end = timer() self.assertTrue((end - start) > 1.0) self.assertEqual(self.mock_payload.do_something.call_count, 10) def test_semaphore_multiple_concurrency(self): start = timer() self._concurrency_core(5, 0.1) end = timer() self.assertTrue((end - start) > 1.0) self.assertEqual(self.mock_payload.do_something.call_count, 10) # do some high speed tests; I don't think we can really assert # much about these other than they don't deadlock... def test_semaphore_fast_no_concurrency(self): self._concurrency_core(None, 0.0) def test_semaphore_fast_single_concurrency(self): self._concurrency_core(1, 0.0) def test_semaphore_fast_multiple_concurrency(self): self._concurrency_core(5, 0.0)