|
2 | 2 | Test scyjava JVM memory-related functions. |
3 | 3 | """ |
4 | 4 |
|
| 5 | +from assertpy import assert_that |
| 6 | + |
5 | 7 | import scyjava |
6 | 8 |
|
7 | 9 | mb_initial = 50 # initial MB of memory to snarf up |
| 10 | +mb_tolerance = 10 # ceiling of expected MB in use |
8 | 11 |
|
9 | 12 | scyjava.config.set_heap_min(mb=mb_initial) |
10 | 13 | scyjava.config.set_heap_max(gb=1) |
|
18 | 21 | mb_total = scyjava.memory_total() // 1024 // 1024 |
19 | 22 | mb_used = scyjava.memory_used() // 1024 // 1024 |
20 | 23 |
|
21 | | -# Used memory should be less than the current memory total, |
22 | | -# which should be less than the maximum heap size. |
23 | | -assert mb_used <= mb_total <= mb_max, f"{mb_used=} {mb_total=} {mb_max=}" |
24 | | - |
25 | | -# The maximum heap size should be approximately 1 GB. |
26 | | -assert 900 <= mb_max <= 1024, f"{mb_max=}" |
27 | | - |
28 | | -# Most of that memory should still be free; i.e., |
29 | | -# we should not be using more than a few MB yet. |
30 | | -assert mb_used <= 5, f"{mb_used=}" |
31 | | - |
32 | | -# The total MB available to Java at this moment |
33 | | -# should be close to our requested initial amount. |
34 | | -assert abs(mb_total - mb_initial) < 5, f"{mb_total=} {mb_initial=}" |
| 24 | +assert_that( |
| 25 | + mb_used, "Used memory should be less than the current memory total" |
| 26 | +).is_less_than_or_equal_to(mb_total) |
| 27 | +assert_that( |
| 28 | + mb_total, "current memory total should be less than maximum memory" |
| 29 | +).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) |
| 31 | + |
| 32 | +assert_that(mb_used, "most memory should be available").is_less_than(mb_tolerance) |
| 33 | +assert_that(mb_total, "total memory should be close to initial").is_close_to( |
| 34 | + mb_initial, tolerance=mb_tolerance |
| 35 | +) |
0 commit comments