-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathtest-server.py
More file actions
136 lines (122 loc) · 4.51 KB
/
test-server.py
File metadata and controls
136 lines (122 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from http.server import BaseHTTPRequestHandler, HTTPServer
import json
backups_response = {
"data": [
{
"backup_id": "6f52240b-6397-481b-9767-748a2d4d3b65",
"source_index_name": "jensparse",
"source_index_id": "71ded150-2b8e-422d-9849-097f2c89d18b",
"status": "Ready",
"cloud": "aws",
"region": "us-east-1",
"tags": {},
"name": "sparsebackup",
"description": "",
"dimension": 0,
"record_count": 10000,
"namespace_count": 1000,
"size_bytes": 123456,
"created_at": "2025-05-15T20:55:29.477794Z",
}
]
}
indexes_response = {
"indexes": [
{
"name": "jhamon-20250515-165135548-reorg-create-with-e",
"metric": "dotproduct",
"host": "jhamon-20250515-165135548-reorg-create-with-e-bt8x3su.svc.aped-4627-b74a.pinecone.io",
"spec": {"serverless": {"cloud": "aws", "region": "us-east-1"}},
"status": {"ready": True, "state": "Ready"},
"vector_type": "sparse",
"dimension": None,
"deletion_protection": "disabled",
"tags": {"env": "dev"},
},
{
"name": "unexpected",
"metric": "newmetric",
"host": "jhamon-20250515-165135548-reorg-create-with-e-bt8x3su.svc.aped-4627-b74a.pinecone.io",
"spec": {"serverless": {"cloud": "aws", "region": "us-east-1"}},
"status": {"ready": False, "state": "UnknownStatus"},
"vector_type": "sparse",
"dimension": -1,
"deletion_protection": "disabled",
"tags": {"env": "dev"},
},
{
"name": "wrong-types",
"metric": 123,
"host": "jhamon-20250515-165135548-reorg-create-with-e-bt8x3su.svc.aped-4627-b74a.pinecone.io",
"spec": {"serverless": {"cloud": "aws", "region": "us-east-1"}},
"status": {"ready": False, "state": "UnknownStatus"},
"vector_type": None,
"dimension": None,
"deletion_protection": "asdf",
"tags": None,
},
]
}
index_description_response = {
"name": "docs-example-dense",
"vector_type": "dense",
"metric": "cosine",
"dimension": 1536,
"status": {"ready": True, "state": "Ready"},
"host": "docs-example-dense-govk0nt.svc.aped-4627-b74a.pinecone.io",
"spec": {"serverless": {"region": "us-east-1", "cloud": "aws"}},
"deletion_protection": "disabled",
"tags": {"environment": "development"},
}
upsert_response = {"upsertedCount": 10}
call_count = 0
class MyHandler(BaseHTTPRequestHandler):
def do_POST(self):
global call_count
call_count += 1
# Simulate a high rate of 500 errors
if call_count % 5 != 0:
self.send_response(500)
self.end_headers()
return
if self.path.startswith("/vectors/upsert"):
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
response = upsert_response
self.wfile.write(json.dumps(response).encode())
else:
self.send_response(404)
self.end_headers()
def do_GET(self):
global call_count
call_count += 1
# Simulate a high rate of 500 errors
if call_count % 5 != 0:
self.send_response(500)
self.end_headers()
return
if self.path.startswith("/backups"):
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
response = backups_response
self.wfile.write(json.dumps(response).encode())
elif self.path.startswith("/indexes/"):
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
response = index_description_response
self.wfile.write(json.dumps(response).encode())
elif self.path.startswith("/indexes"):
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
response = indexes_response
self.wfile.write(json.dumps(response).encode())
else:
self.send_response(404)
self.end_headers()
server = HTTPServer(("localhost", 8000), MyHandler)
print("Serving on http://localhost:8000")
server.serve_forever()