|
| 1 | +""" |
| 2 | +Test that ALS initial memory footprint does not exceed a |
| 3 | +given amount of memory when runtime indexing is |
| 4 | +disabled. |
| 5 | +""" |
| 6 | + |
| 7 | +from drivers.pylsp import ( |
| 8 | + ALSLanguageClient, |
| 9 | + ALSClientServerConfig, |
| 10 | + test, |
| 11 | + get_ALS_memory_footprint, |
| 12 | +) |
| 13 | +import os |
| 14 | + |
| 15 | + |
| 16 | +async def check_memory_footprint( |
| 17 | + lsp: ALSLanguageClient, |
| 18 | + footprint_lower_bound, |
| 19 | + footprint_upper_bound, |
| 20 | +): |
| 21 | + """ |
| 22 | + This checks that the ALS memory footprint is within the given bounds. |
| 23 | + The bounds should be expresed in MB. |
| 24 | + """ |
| 25 | + # Send a didOpen for main.adb |
| 26 | + lsp.didOpenFile("main.adb") |
| 27 | + |
| 28 | + # Wait for indexing |
| 29 | + await lsp.awaitIndexingEnd() |
| 30 | + |
| 31 | + # Check the memory footprint in MB (psutil returns memory info in Bytes): verify |
| 32 | + # that the initial footprint is within expected bounds |
| 33 | + mem_footprint = get_ALS_memory_footprint() |
| 34 | + |
| 35 | + assert footprint_lower_bound < mem_footprint < footprint_upper_bound, ( |
| 36 | + f"Initial memory footprint should be between {footprint_lower_bound}MB " |
| 37 | + + f"and {footprint_upper_bound}MB. Actual memory is: {mem_footprint}MB" |
| 38 | + ) |
| 39 | + |
| 40 | + |
| 41 | +@test( |
| 42 | + config=ALSClientServerConfig( |
| 43 | + [ |
| 44 | + os.environ.get("ALS", "ada_language_server"), |
| 45 | + "--tracefile", |
| 46 | + "./traces_with_runtime_indexing.cfg", |
| 47 | + ] |
| 48 | + ) |
| 49 | +) |
| 50 | +async def test_with_indexing(lsp: ALSLanguageClient) -> None: |
| 51 | + await check_memory_footprint( |
| 52 | + lsp, footprint_lower_bound=600, footprint_upper_bound=650 |
| 53 | + ) |
| 54 | + |
| 55 | + |
| 56 | +@test( |
| 57 | + config=ALSClientServerConfig( |
| 58 | + [ |
| 59 | + os.environ.get("ALS", "ada_language_server"), |
| 60 | + "--tracefile", |
| 61 | + "./traces_without_runtime_indexing.cfg", |
| 62 | + ] |
| 63 | + ) |
| 64 | +) |
| 65 | +async def test_without_indexing(lsp: ALSLanguageClient) -> None: |
| 66 | + await check_memory_footprint( |
| 67 | + lsp, footprint_lower_bound=70, footprint_upper_bound=150 |
| 68 | + ) |
0 commit comments