Skip to content

Commit 3a9d324

Browse files
committed
test: extend container basic to verify resource limits
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent ad79f66 commit 3a9d324

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

test/case/containers/basic/test.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ image::topology.svg[Container basic topology, align=center, scaledwidth=75%]
2121
. Create container 'web' from bundled OCI image
2222
. Verify container 'web' has started
2323
. Verify container 'web' is reachable on http://container-host.local:91
24+
. Verify resource constraints and usage are available
2425
. Stop container 'web'
2526
. Verify container 'web' is stopped
2627
. Restart container 'web'

test/case/containers/basic/test.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from infamy.util import until, curl
1212

1313

14-
def _verify(server):
14+
def _verify(server, silent=False):
1515
# TODO: Should really use mDNS here....
1616
url = f"http://[{server}]:91/index.html"
17-
response = curl(url)
17+
response = curl(url, silent=silent)
1818
return response is not None and "It works" in response
1919

2020

@@ -46,6 +46,10 @@ def _verify(server):
4646
"command": "/usr/sbin/httpd -f -v -p 91",
4747
"network": {
4848
"host": True
49+
},
50+
"resource-limit": {
51+
"memory": 512, # 512 KiB
52+
"cpu": 50000 # 50% of one CPU
4953
}
5054
}
5155
]
@@ -57,7 +61,23 @@ def _verify(server):
5761
until(lambda: c.running(NAME), attempts=60)
5862

5963
with test.step("Verify container 'web' is reachable on http://container-host.local:91"):
60-
until(lambda: _verify(addr), attempts=10)
64+
until(lambda: _verify(addr, silent=True), attempts=10)
65+
66+
with test.step("Verify resource constraints and usage are available"):
67+
data = target.get_data("/infix-containers:containers")
68+
containers = data.get("containers", {}).get("container", [])
69+
web = next((c for c in containers if c["name"] == NAME), None)
70+
71+
limits = web.get("resource-limit", {})
72+
assert limits.get("memory") == 512, "Memory limit not set correctly"
73+
assert limits.get("cpu") == 50000, "CPU limit not set correctly"
74+
75+
rusage = web.get("resource-usage", {})
76+
assert rusage is not None, "Resource usage data not available"
77+
78+
mem_used = rusage.get("memory")
79+
assert mem_used is not None, "Memory usage not reported"
80+
print(f"Container using {mem_used} KiB memory")
6181

6282
with test.step("Stop container 'web'"):
6383
c = infamy.Container(target)
@@ -71,5 +91,5 @@ def _verify(server):
7191

7292
with test.step("Verify container 'web' is reachable on http://container-host.local:91"):
7393
# Wait for it to restart and respond, or fail
74-
until(lambda: _verify(addr), attempts=60)
94+
until(lambda: _verify(addr, silent=True), attempts=60)
7595
test.succeed()

0 commit comments

Comments
 (0)