orionis 0.406.0__py3-none-any.whl → 0.407.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orionis/metadata/framework.py +1 -1
- orionis/services/asynchrony/contracts/coroutines.py +13 -5
- orionis/services/asynchrony/coroutines.py +33 -29
- orionis/services/asynchrony/exceptions/exception.py +9 -1
- orionis/services/environment/core/dot_env.py +46 -34
- orionis/services/environment/enums/__init__.py +0 -0
- orionis/services/environment/enums/cast_type.py +42 -0
- orionis/services/environment/serializer/__init__.py +0 -0
- orionis/services/environment/serializer/values.py +21 -0
- orionis/services/environment/validators/__init__.py +0 -0
- orionis/services/environment/validators/key_name.py +46 -0
- orionis/services/environment/validators/types.py +45 -0
- orionis/services/system/contracts/imports.py +38 -18
- orionis/services/system/contracts/workers.py +29 -12
- orionis/services/system/imports.py +65 -25
- orionis/services/system/runtime/imports.py +18 -9
- orionis/services/system/workers.py +49 -16
- orionis/test/output/dumper.py +1 -0
- {orionis-0.406.0.dist-info → orionis-0.407.0.dist-info}/METADATA +1 -1
- {orionis-0.406.0.dist-info → orionis-0.407.0.dist-info}/RECORD +30 -23
- tests/example/test_example.py +2 -2
- tests/metadata/test_metadata_framework.py +71 -6
- tests/metadata/test_metadata_package.py +55 -10
- tests/services/asynchrony/test_services_asynchrony_coroutine.py +52 -7
- tests/services/system/test_services_system_imports.py +119 -16
- tests/services/system/test_services_system_workers.py +71 -30
- {orionis-0.406.0.dist-info → orionis-0.407.0.dist-info}/WHEEL +0 -0
- {orionis-0.406.0.dist-info → orionis-0.407.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.406.0.dist-info → orionis-0.407.0.dist-info}/top_level.txt +0 -0
- {orionis-0.406.0.dist-info → orionis-0.407.0.dist-info}/zip-safe +0 -0
|
@@ -3,88 +3,129 @@ from orionis.services.system.workers import Workers
|
|
|
3
3
|
from orionis.test.cases.asynchronous import AsyncTestCase
|
|
4
4
|
|
|
5
5
|
class TestServicesSystemWorkers(AsyncTestCase):
|
|
6
|
-
"""
|
|
7
|
-
Unit tests for the Workers class.
|
|
8
|
-
|
|
9
|
-
This test suite verifies the correct calculation of the number of workers
|
|
10
|
-
based on available CPU and RAM resources.
|
|
11
|
-
|
|
12
|
-
Methods
|
|
13
|
-
-------
|
|
14
|
-
testCalculateCpuLimited()
|
|
15
|
-
Test when the number of workers is limited by CPU count.
|
|
16
|
-
testCalculateRamLimited()
|
|
17
|
-
Test when the number of workers is limited by available RAM.
|
|
18
|
-
testCalculateExactFit()
|
|
19
|
-
Test when CPU and RAM allow for the same number of workers.
|
|
20
|
-
testCalculateLowRam()
|
|
21
|
-
Test when low RAM restricts the number of workers to less than CPU count.
|
|
22
|
-
"""
|
|
23
6
|
|
|
24
7
|
@patch('multiprocessing.cpu_count', return_value=8)
|
|
25
8
|
@patch('psutil.virtual_memory')
|
|
26
9
|
def testCalculateCpuLimited(self, mockVm, mockCpuCount):
|
|
27
10
|
"""
|
|
28
|
-
|
|
11
|
+
Tests worker calculation when CPU count is the limiting factor.
|
|
29
12
|
|
|
30
|
-
Simulates 8 CPUs and 16 GB RAM,
|
|
31
|
-
RAM
|
|
13
|
+
Simulates a system with 8 CPUs and 16 GB RAM, where each worker requires 1 GB of RAM.
|
|
14
|
+
Although the available RAM could support up to 16 workers, the CPU count restricts the number
|
|
15
|
+
of workers to 8.
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
mockVm : unittest.mock.Mock
|
|
20
|
+
Mock object for `psutil.virtual_memory`.
|
|
21
|
+
mockCpuCount : unittest.mock.Mock
|
|
22
|
+
Mock object for `multiprocessing.cpu_count`.
|
|
32
23
|
|
|
33
24
|
Returns
|
|
34
25
|
-------
|
|
35
26
|
None
|
|
27
|
+
Asserts that the calculated number of workers is limited by CPU count.
|
|
36
28
|
"""
|
|
29
|
+
|
|
30
|
+
# Set the mocked total RAM to 16 GB
|
|
37
31
|
mockVm.return_value.total = 16 * 1024 ** 3
|
|
32
|
+
|
|
33
|
+
# Create Workers instance with 1 GB RAM required per worker
|
|
38
34
|
workers = Workers(ram_per_worker=1)
|
|
35
|
+
|
|
36
|
+
# Assert that the number of workers is limited to 8 by CPU count
|
|
39
37
|
self.assertEqual(workers.calculate(), 8)
|
|
40
38
|
|
|
41
39
|
@patch('multiprocessing.cpu_count', return_value=32)
|
|
42
40
|
@patch('psutil.virtual_memory')
|
|
43
41
|
def testCalculateRamLimited(self, mockVm, mockCpuCount):
|
|
44
42
|
"""
|
|
45
|
-
|
|
43
|
+
Tests worker calculation when RAM is the limiting factor.
|
|
46
44
|
|
|
47
|
-
Simulates 32 CPUs and 4 GB RAM,
|
|
48
|
-
|
|
45
|
+
Simulates a system with 32 CPUs and 4 GB RAM, where each worker requires 1 GB of RAM.
|
|
46
|
+
Although the CPU count could support up to 32 workers, the available RAM restricts the number
|
|
47
|
+
of workers to 4.
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
mockVm : unittest.mock.Mock
|
|
52
|
+
Mock object for `psutil.virtual_memory`.
|
|
53
|
+
mockCpuCount : unittest.mock.Mock
|
|
54
|
+
Mock object for `multiprocessing.cpu_count`.
|
|
49
55
|
|
|
50
56
|
Returns
|
|
51
57
|
-------
|
|
52
58
|
None
|
|
59
|
+
Asserts that the calculated number of workers is limited by available RAM.
|
|
53
60
|
"""
|
|
61
|
+
|
|
62
|
+
# Set the mocked total RAM to 4 GB
|
|
54
63
|
mockVm.return_value.total = 4 * 1024 ** 3
|
|
64
|
+
|
|
65
|
+
# Create Workers instance with 1 GB RAM required per worker
|
|
55
66
|
workers = Workers(ram_per_worker=1)
|
|
67
|
+
|
|
68
|
+
# Assert that the number of workers is limited to 4 by available RAM
|
|
56
69
|
self.assertEqual(workers.calculate(), 4)
|
|
57
70
|
|
|
58
71
|
@patch('multiprocessing.cpu_count', return_value=4)
|
|
59
72
|
@patch('psutil.virtual_memory')
|
|
60
73
|
def testCalculateExactFit(self, mockVm, mockCpuCount):
|
|
61
74
|
"""
|
|
62
|
-
|
|
75
|
+
Tests worker calculation when both CPU count and available RAM allow for the same number of workers.
|
|
63
76
|
|
|
64
|
-
Simulates 4 CPUs and 2 GB RAM,
|
|
65
|
-
RAM
|
|
77
|
+
Simulates a system with 4 CPUs and 2 GB RAM, where each worker requires 0.5 GB of RAM.
|
|
78
|
+
Both CPU and RAM resources permit exactly 4 workers, so the calculation should return 4.
|
|
79
|
+
|
|
80
|
+
Parameters
|
|
81
|
+
----------
|
|
82
|
+
mockVm : unittest.mock.Mock
|
|
83
|
+
Mock object for `psutil.virtual_memory`.
|
|
84
|
+
mockCpuCount : unittest.mock.Mock
|
|
85
|
+
Mock object for `multiprocessing.cpu_count`.
|
|
66
86
|
|
|
67
87
|
Returns
|
|
68
88
|
-------
|
|
69
89
|
None
|
|
90
|
+
Asserts that the calculated number of workers is 4, matching both CPU and RAM constraints.
|
|
70
91
|
"""
|
|
92
|
+
# Set the mocked total RAM to 2 GB
|
|
71
93
|
mockVm.return_value.total = 2 * 1024 ** 3
|
|
94
|
+
|
|
95
|
+
# Create Workers instance with 0.5 GB RAM required per worker
|
|
72
96
|
workers = Workers(ram_per_worker=0.5)
|
|
97
|
+
|
|
98
|
+
# Assert that the number of workers is limited to 4 by both CPU and RAM
|
|
73
99
|
self.assertEqual(workers.calculate(), 4)
|
|
74
100
|
|
|
75
101
|
@patch('multiprocessing.cpu_count', return_value=2)
|
|
76
102
|
@patch('psutil.virtual_memory')
|
|
77
103
|
def testCalculateLowRam(self, mockVm, mockCpuCount):
|
|
78
104
|
"""
|
|
79
|
-
|
|
105
|
+
Tests worker calculation when available RAM is lower than CPU count, restricting the number of workers.
|
|
106
|
+
|
|
107
|
+
Simulates a system with 2 CPUs and 0.7 GB RAM, where each worker requires 0.5 GB of RAM.
|
|
108
|
+
Although the CPU count could support up to 2 workers, the available RAM restricts the number
|
|
109
|
+
of workers to 1.
|
|
80
110
|
|
|
81
|
-
|
|
82
|
-
|
|
111
|
+
Parameters
|
|
112
|
+
----------
|
|
113
|
+
mockVm : unittest.mock.Mock
|
|
114
|
+
Mock object for `psutil.virtual_memory`.
|
|
115
|
+
mockCpuCount : unittest.mock.Mock
|
|
116
|
+
Mock object for `multiprocessing.cpu_count`.
|
|
83
117
|
|
|
84
118
|
Returns
|
|
85
119
|
-------
|
|
86
120
|
None
|
|
121
|
+
Asserts that the calculated number of workers is limited to 1 by available RAM.
|
|
87
122
|
"""
|
|
123
|
+
|
|
124
|
+
# Set the mocked total RAM to 0.7 GB
|
|
88
125
|
mockVm.return_value.total = 0.7 * 1024 ** 3
|
|
126
|
+
|
|
127
|
+
# Create Workers instance with 0.5 GB RAM required per worker
|
|
89
128
|
workers = Workers(ram_per_worker=0.5)
|
|
90
|
-
|
|
129
|
+
|
|
130
|
+
# Assert that the number of workers is limited to 1 by available RAM
|
|
131
|
+
self.assertEqual(workers.calculate(), 1)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|