|
| 1 | +// vtest build: !docker-ubuntu-musl |
| 2 | +import os |
| 3 | +import time |
| 4 | +import net.http |
| 5 | + |
| 6 | +const sport = 13085 |
| 7 | +const localserver = '127.0.0.1:${sport}' |
| 8 | +const exit_after_time = 30000 |
| 9 | +const vexe = os.getenv('VEXE') |
| 10 | +const vroot = os.dir(vexe) |
| 11 | +const serverexe = os.join_path(os.cache_dir(), 'veb_memory_test_server.exe') |
| 12 | + |
| 13 | +fn testsuite_begin() { |
| 14 | + os.chdir(vroot) or {} |
| 15 | + if os.exists(serverexe) { |
| 16 | + os.rm(serverexe) or {} |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +fn testsuite_end() { |
| 21 | + if os.exists(serverexe) { |
| 22 | + os.rm(serverexe) or {} |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +fn test_server_compiles() { |
| 27 | + did_compile := os.system('${os.quoted_path(vexe)} -o ${os.quoted_path(serverexe)} vlib/veb/tests/memory_leak_test_server.v') |
| 28 | + assert did_compile == 0 |
| 29 | + assert os.exists(serverexe) |
| 30 | +} |
| 31 | + |
| 32 | +fn test_server_runs_in_background() { |
| 33 | + spawn os.system('${os.quoted_path(serverexe)} ${sport} ${exit_after_time}') |
| 34 | + time.sleep(500 * time.millisecond) |
| 35 | +} |
| 36 | + |
| 37 | +fn test_large_responses_work_correctly() { |
| 38 | + // Make requests with large response bodies and verify they work |
| 39 | + request_count := 20 |
| 40 | + mut successful := 0 |
| 41 | + for _ in 0 .. request_count { |
| 42 | + resp := http.get('http://${localserver}/large') or { continue } |
| 43 | + if resp.status_code == 200 && resp.body.len > 50000 { |
| 44 | + successful += 1 |
| 45 | + } |
| 46 | + } |
| 47 | + // Ensure most requests succeeded (allows for some network variability) |
| 48 | + assert successful >= request_count - 2, 'Only ${successful}/${request_count} requests succeeded' |
| 49 | +} |
| 50 | + |
| 51 | +fn test_heap_usage_endpoint_works() { |
| 52 | + resp := http.get('http://${localserver}/heap') or { |
| 53 | + assert false, 'Failed to get heap usage: ${err}' |
| 54 | + return |
| 55 | + } |
| 56 | + heap := resp.body.i64() |
| 57 | + // Just verify we get a reasonable value (more than 1MB, less than 1GB) |
| 58 | + assert heap > 1024 * 1024, 'Heap usage ${heap} seems too low' |
| 59 | + assert heap < 1024 * 1024 * 1024, 'Heap usage ${heap} seems too high' |
| 60 | +} |
| 61 | + |
| 62 | +fn test_gc_collect_endpoint_works() { |
| 63 | + resp := http.get('http://${localserver}/gc') or { |
| 64 | + assert false, 'Failed to trigger GC: ${err}' |
| 65 | + return |
| 66 | + } |
| 67 | + assert resp.status_code == 200 |
| 68 | +} |
0 commit comments