Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #281 from jjnicola/available
Browse files Browse the repository at this point in the history
Use available memory instead of free memory
  • Loading branch information
bjoernricks committed Jun 9, 2020
2 parents 2082fec + 7f52f6d commit 408a02b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add [pontos](https://github.com/greenbone/pontos) as dev dependency for
managing the version information in ospd [#254](https://github.com/greenbone/ospd/pull/254)
- Add more info about scan progress with progress attribute in get_scans cmd. [#266](https://github.com/greenbone/ospd/pull/266)
- Add support for scan queuing
[#278](https://github.com/greenbone/ospd/pull/278)
[#279](https://github.com/greenbone/ospd/pull/279)
[#281](https://github.com/greenbone/ospd/pull/281)

### Changes
- Modify __init__() method and use new syntax for super(). [#186](https://github.com/greenbone/ospd/pull/186)
Expand Down
2 changes: 1 addition & 1 deletion ospd/ospd.py
Expand Up @@ -1275,7 +1275,7 @@ def is_enough_free_memory(self) -> bool:
if not self.min_free_mem_scan_queue:
return True

free_mem = psutil.virtual_memory().free / (1024 * 1024)
free_mem = psutil.virtual_memory().available / (1024 * 1024)

if free_mem > self.min_free_mem_scan_queue:
return True
Expand Down
4 changes: 2 additions & 2 deletions tests/helper.py
Expand Up @@ -39,8 +39,8 @@ def assert_called(mock: Mock):


class FakePsutil:
def __init__(self, free=None):
self.free = free
def __init__(self, available=None):
self.available = available


class FakeStream:
Expand Down
8 changes: 6 additions & 2 deletions tests/test_scan_and_result.py
Expand Up @@ -1111,15 +1111,19 @@ def test_is_new_scan_allowed_true(self):
def test_free_memory_true(self, mock_psutil):
self.daemon.min_free_mem_scan_queue = 1000
# 1.5 GB free
mock_psutil.virtual_memory.return_value = FakePsutil(free=1500000000)
mock_psutil.virtual_memory.return_value = FakePsutil(
available=1500000000
)

self.assertTrue(self.daemon.is_enough_free_memory())

@patch("ospd.ospd.psutil")
def test_free_memory_false(self, mock_psutil):
self.daemon.min_free_mem_scan_queue = 2000
# 1.5 GB free
mock_psutil.virtual_memory.return_value = FakePsutil(free=1500000000)
mock_psutil.virtual_memory.return_value = FakePsutil(
available=1500000000
)

self.assertFalse(self.daemon.is_enough_free_memory())

Expand Down

0 comments on commit 408a02b

Please sign in to comment.