8000 fix: loosen tolerance for comparing memory consumption · scijava/scyjava@56df799 · GitHub
[go: up one dir, main page]

Skip to content

Commit 56df799

Browse files
committed
fix: loosen tolerance for comparing memory consumption
1 parent a1e48da commit 56df799

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

tests/it/java_heap.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
"""
2-
Test scyjava JVM memory-related functions.
3-
"""
4-
import math
5-
from assertpy import assert_that
2+
Test scyjava JVM memory-related functions.
3+
"""
4+
import math
5+
from assertpy import assert_that
6+
7+
import scyjava
8+
9+
10+
def magnitude(x: int) -> int:
11+
return math.floor(math.log10(abs(x)))
12+
613

7-
import scyjava
14+
mb_initial = 50 # initial MB of memory to snarf up
815

9-
mb_initial = 50 # initial MB of memory to snarf up
16+
scyjava.config.set_heap_min(mb=mb_initial)
17+
scyjava.config.set_heap_max(gb=1)
1018

11-
scyjava.config.set_heap_min(mb=mb_initial)
12-
scyjava.config.set_heap_max(gb=1)
19+
assert not scyjava.jvm_started()
20+
scyjava.start_jvm()
1321

14-
assert not scyjava.jvm_started()
15-
scyjava.start_jvm()
22+
assert scyjava.available_processors() >= 1
1623

17-
assert scyjava.available_processors() >= 1
24+
mb_max = scyjava.memory_max() // 1024 // 1024
25+
mb_total = scyjava.memory_total() // 1024 // 1024
26+
mb_used = scyjava.memory_used() // 1024 // 1024
1827

19-
mb_max = scyjava.memory_max() // 1024 // 1024
20-
mb_total = scyjava.memory_total() // 1024 // 1024
21-
mb_used = scyjava.memory_used() // 1024 // 1024
28+
assert_that(mb_used, 'Used memory should be less than the current memory total').is_less_than_or_equal_to(mb_total)
29+
assert_that(mb_total, 'current memory total should be less than maximum memory').is_less_than_or_equal_to(mb_max)
30+
assert_that(mb_max, 'maximum heap size should be approx. 1 GB').is_between(900, 1024)
2231

23-
assert_that(mb_used, 'Used memory should be less than the current memory total').is_less_than_or_equal_to(mb_total)
24-
assert_that(mb_total, 'current memory total should be less than maximum memory').is_less_than_or_equal_to(mb_max)
25-
assert_that(mb_max, 'maximum heap size should be approx. 1 GB').is_between(900, 1024)
32+
tolerance = pow(10, magnitude(mb_initial))
2633

27-
assert_that(mb_used, 'most memory should be available').is_less_than(5)
28-
assert_that(mb_total, 'total memory should be close to initial').is_close_to(mb_initial, tolerance=5)
34+
assert_that(mb_used, 'most memory should be available').is_less_than(tolerance)
35+
assert_that(mb_total, 'total memory should be close to initial').is_close_to(mb_initial, tolerance=tolerance)

0 commit comments

Comments
 (0)
0