コード例 #1
0
 def test_calculate_workers_max(self, max_workers: str | None) -> None:
     """Test Gunicorn worker process calculation with custom maximum."""
     cores = multiprocessing.cpu_count()
     default = max(cores, 2)
     result = gunicorn_conf.calculate_workers(max_workers, None)
     if max_workers and default > (m := int(max_workers)):
         assert result == m
コード例 #2
0
 def test_calculate_workers_both_max_and_total(self, max_workers: str,
                                               total_workers: str) -> None:
     """Test Gunicorn worker process calculation if max workers and total workers
     (web concurrency) are both set. Worker number should be the lesser of the two.
     """
     result = gunicorn_conf.calculate_workers(max_workers, total_workers)
     assert result == min(int(max_workers), int(total_workers))
コード例 #3
0
 def test_calculate_workers_both_max_and_workers_per_core(
         self, max_workers: str, workers_per_core: str) -> None:
     """Test Gunicorn worker process calculation if max workers and workers per core
     are both set. Worker number should always be less than the maximum.
     """
     result = gunicorn_conf.calculate_workers(
         max_workers, None, workers_per_core=workers_per_core)
     assert result <= int(max_workers)
コード例 #4
0
 def test_calculate_workers_per_core(self, workers_per_core: str) -> None:
     """Test Gunicorn worker process calculation with custom workers per core.
     Worker number should be the greater of 2 or the workers per core setting.
     """
     cores = multiprocessing.cpu_count()
     result = gunicorn_conf.calculate_workers(
         workers_per_core=workers_per_core)
     assert result == max(int(float(workers_per_core) * cores), 2)
コード例 #5
0
ファイル: test_start.py プロジェクト: includeamin/inboard
 def test_gunicorn_conf_workers_custom_cores(
         self, monkeypatch: MonkeyPatch) -> None:
     """Test custom Gunicorn worker process calculation."""
     monkeypatch.setenv("WORKERS_PER_CORE", "0.5")
     assert os.getenv("WORKERS_PER_CORE") == "0.5"
     cores: int = multiprocessing.cpu_count()
     assert gunicorn_conf.calculate_workers(
         None, "2", str(os.getenv("WORKERS_PER_CORE")),
         cores=cores) == max(int(cores * 0.5), 2)
コード例 #6
0
ファイル: test_start.py プロジェクト: includeamin/inboard
 def test_gunicorn_conf_workers_custom_concurrency(
         self, monkeypatch: MonkeyPatch, number_of_workers: str) -> None:
     """Test custom Gunicorn worker process calculation."""
     monkeypatch.setenv("WEB_CONCURRENCY", number_of_workers)
     monkeypatch.setenv("WORKERS_PER_CORE", "0.5")
     assert os.getenv("WEB_CONCURRENCY") == number_of_workers
     assert os.getenv("WORKERS_PER_CORE") == "0.5"
     assert (gunicorn_conf.calculate_workers(
         None,
         str(os.getenv("WEB_CONCURRENCY")),
         str(os.getenv("WORKERS_PER_CORE")),
     ) == int(number_of_workers))
コード例 #7
0
ファイル: test_start.py プロジェクト: includeamin/inboard
 def test_gunicorn_conf_workers_custom_max(
         self, monkeypatch: MonkeyPatch) -> None:
     """Test custom Gunicorn worker process calculation."""
     monkeypatch.setenv("MAX_WORKERS", "1")
     monkeypatch.setenv("WEB_CONCURRENCY", "4")
     monkeypatch.setenv("WORKERS_PER_CORE", "0.5")
     assert os.getenv("MAX_WORKERS") == "1"
     assert os.getenv("WEB_CONCURRENCY") == "4"
     assert os.getenv("WORKERS_PER_CORE") == "0.5"
     assert (gunicorn_conf.calculate_workers(
         str(os.getenv("MAX_WORKERS")),
         str(os.getenv("WEB_CONCURRENCY")),
         str(os.getenv("WORKERS_PER_CORE")),
     ) == 1)
コード例 #8
0
 def test_calculate_workers_total(self, total_workers: str | None) -> None:
     """Test Gunicorn worker process calculation with custom total."""
     cores = multiprocessing.cpu_count()
     result = gunicorn_conf.calculate_workers(None, total_workers)
     assert result == int(total_workers) if total_workers else max(cores, 2)