MCPcopy Create free account
hub / github.com/deepclause/agentvm / test

Function test

test-download-perf.js:7–63  ·  view source on GitHub ↗

* Test download performance to verify networking improvements

()

Source from the content-addressed store, hash-verified

5 */
6
7async function test() {
8 console.log("=== Download Performance Test ===\n");
9
10 const vm = new AgentVM({ network: true, debug: false });
11
12 try {
13 console.log("Starting VM...");
14 await vm.start();
15 console.log("VM started.\n");
16
17 // Test 1: Small file - Alpine APKINDEX (compressed ~500KB)
18 console.log("Test 1: Download Alpine APKINDEX (~500KB compressed)");
19 let start = Date.now();
20 let res = await vm.exec('curl -s https://dl-cdn.alpinelinux.org/alpine/v3.23/community/x86_64/APKINDEX.tar.gz -o /tmp/apkindex.tar.gz && ls -la /tmp/apkindex.tar.gz');
21 let elapsed = Date.now() - start;
22 console.log(` Result (${elapsed}ms):`);
23 console.log(` stdout: ${res.stdout}`);
24 if (res.stderr) console.log(` stderr: ${res.stderr}`);
25 console.log();
26
27 // Test 2: Get file size
28 console.log("Test 2: Verify file size");
29 res = await vm.exec('wc -c < /tmp/apkindex.tar.gz');
30 const size = parseInt(res.stdout.trim(), 10);
31 console.log(` Downloaded ${size} bytes`);
32 console.log(` Speed: ${(size / 1024 / (elapsed / 1000)).toFixed(1)} KB/s\n`);
33
34 // Test 3: Test with wget instead of curl
35 console.log("Test 3: Download with wget");
36 start = Date.now();
37 res = await vm.exec('wget -q -O /tmp/apkindex2.tar.gz https://dl-cdn.alpinelinux.org/alpine/v3.23/community/x86_64/APKINDEX.tar.gz');
38 elapsed = Date.now() - start;
39 console.log(` Result (${elapsed}ms):`);
40 console.log(` exitCode: ${res.exitCode}`);
41
42 res = await vm.exec('wc -c < /tmp/apkindex2.tar.gz');
43 const size2 = parseInt(res.stdout.trim(), 10);
44 console.log(` Downloaded ${size2} bytes`);
45 console.log(` Speed: ${(size2 / 1024 / (elapsed / 1000)).toFixed(1)} KB/s\n`);
46
47 // Test 4: Download httpbin binary data
48 console.log("Test 4: Download 100KB from httpbin");
49 start = Date.now();
50 res = await vm.exec('curl -s http://httpbin.org/bytes/102400 -o /tmp/100kb.bin && wc -c < /tmp/100kb.bin');
51 elapsed = Date.now() - start;
52 const size4 = parseInt(res.stdout.trim(), 10);
53 console.log(` Downloaded ${size4} bytes in ${elapsed}ms`);
54 console.log(` Speed: ${(size4 / 1024 / (elapsed / 1000)).toFixed(1)} KB/s\n`);
55
56 console.log("=== Tests Complete ===");
57
58 } catch (err) {
59 console.error("Error:", err);
60 } finally {
61 await vm.stop();
62 }
63}
64

Callers 1

Calls 3

startMethod · 0.95
execMethod · 0.95
stopMethod · 0.95

Tested by

no test coverage detected