Skip to content

Commit d41404a

Browse files
committed
test: add e2e session/sandbox lifecycle tests
Add session_lifecycle_test.go covering the scenarios from issue #103: - A1 (TestAgentRuntimeSessionCreationAndReuse): verifies that a first invocation without x-agentcube-session-id returns HTTP 200 plus a non-empty session ID header, and that a second invocation using that ID returns the same session ID (reuse). - A2 (TestAgentRuntimeMissingRuntime): asserts that calling a non-existent AgentRuntime returns HTTP 404 with a clear error body. - A3 (TestSessionSandboxLifecycleTTL): smoke test for idle-TTL semantics; creates a session, confirms it is still alive before TTL, then waits past TTL + GC window and asserts the session is gone. Skipped automatically under go test -short. - B1 (TestCodeInterpreterSessionAutoCreation): verifies that the Router auto-creates a session when no x-agentcube-session-id is sent, and sets the header in the response. - B2 (TestCodeInterpreterStatefulSession): verifies that state written to the shared workspace in one call is visible in the next call of the same session. Also adds echo_agent_short_ttl.yaml, an AgentRuntime CR identical to echo-agent but with sessionTimeout: 30s, required by the A3 TTL test. Fixes #103 Signed-off-by: Jagjeevan Kashid <jagjeevandev97@gmail.com>
1 parent 8ebae9b commit d41404a

2 files changed

Lines changed: 634 additions & 0 deletions

File tree

test/e2e/echo_agent_short_ttl.yaml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
apiVersion: runtime.agentcube.volcano.sh/v1alpha1
2+
kind: AgentRuntime
3+
metadata:
4+
name: echo-agent-short-ttl
5+
namespace: agentcube
6+
spec:
7+
targetPort:
8+
- pathPrefix: "/echo"
9+
port: 8080
10+
protocol: "HTTP"
11+
podTemplate:
12+
labels:
13+
app: echo-agent-short-ttl
14+
test: e2e
15+
spec:
16+
containers:
17+
- name: echo-server
18+
image: python:3.9-slim
19+
ports:
20+
- containerPort: 8080
21+
protocol: TCP
22+
readinessProbe:
23+
httpGet:
24+
path: /echo
25+
port: 8080
26+
initialDelaySeconds: 5
27+
periodSeconds: 5
28+
timeoutSeconds: 3
29+
successThreshold: 1
30+
failureThreshold: 3
31+
livenessProbe:
32+
httpGet:
33+
path: /echo
34+
port: 8080
35+
initialDelaySeconds: 10
36+
periodSeconds: 10
37+
timeoutSeconds: 5
38+
successThreshold: 1
39+
failureThreshold: 3
40+
command: ["python3", "-c"]
41+
args:
42+
- |
43+
import http.server
44+
import socketserver
45+
import json
46+
import sys
47+
48+
class EchoHandler(http.server.BaseHTTPRequestHandler):
49+
def do_POST(self):
50+
if self.path.startswith('/echo'):
51+
try:
52+
content_length = int(self.headers['Content-Length'])
53+
post_data = self.rfile.read(content_length)
54+
request_data = json.loads(post_data.decode('utf-8'))
55+
input_text = request_data.get('input', '')
56+
57+
response = {
58+
'output': f'echo: {input_text}',
59+
'metadata': {
60+
'echoed': True,
61+
'original_input': input_text
62+
}
63+
}
64+
65+
self.send_response(200)
66+
self.send_header('Content-Type', 'application/json')
67+
self.end_headers()
68+
self.wfile.write(json.dumps(response).encode('utf-8'))
69+
except Exception as e:
70+
self.send_response(400)
71+
self.send_header('Content-Type', 'application/json')
72+
self.end_headers()
73+
self.wfile.write(json.dumps({'error': str(e)}).encode('utf-8'))
74+
else:
75+
self.send_response(404)
76+
self.send_header('Content-Type', 'application/json')
77+
self.end_headers()
78+
self.wfile.write(b'{"error": "Not found"}')
79+
80+
def do_GET(self):
81+
if self.path == '/echo':
82+
# Health check for livenessProbe and readinessProbe
83+
self.send_response(200)
84+
self.send_header('Content-Type', 'application/json')
85+
self.end_headers()
86+
self.wfile.write(b'{"status": "healthy"}')
87+
else:
88+
self.send_response(404)
89+
self.send_header('Content-Type', 'application/json')
90+
self.end_headers()
91+
self.wfile.write(b'{"error": "Not found"}')
92+
93+
def log_message(self, format, *args):
94+
# Suppress server logs
95+
pass
96+
97+
with socketserver.TCPServer(("0.0.0.0", 8080), EchoHandler) as httpd:
98+
print("Echo server started on port 8080")
99+
httpd.serve_forever()
100+
# Very short idle TTL – used by TestSessionSandboxLifecycleTTL (A3) to verify
101+
# that expired sessions are properly invalidated by the garbage collector.
102+
sessionTimeout: "30s"
103+
maxSessionDuration: "8h"
104+
status: {}

0 commit comments

Comments
 (0)