oedb-backend/doc/api_load_test.md
2025-09-18 22:30:25 +02:00

216 lines
No EOL
9.8 KiB
Markdown

# Test Plan for OpenEventDatabase Enhancements
This document outlines a test plan for verifying the functionality of the caching, rate limiting, and search features implemented in the OpenEventDatabase API.
## Prerequisites
- The OpenEventDatabase server is running on `http://127.0.0.1:8080`
- The database is properly configured and contains some test events
- You have a tool for making HTTP requests (e.g., curl, Postman, or a web browser)
## 1. Testing Caching Behavior
### 1.1 Test GET /event Caching
1. Make a GET request to `/event`:
```bash
curl -v http://127.0.0.1:8080/event
```
2. Check the response headers for `Cache-Control` header with `max-age=60`
3. Make the same request again within 60 seconds and observe the response time (should be faster)
4. Make the same request with a unique query parameter to bypass the cache:
```bash
curl -v "http://127.0.0.1:8080/event?_=$(date +%s)"
```
5. Observe that the response is not served from cache (response time should be slower)
### 1.2 Test GET /stats Caching
1. Make a GET request to `/stats`:
```bash
curl -v http://127.0.0.1:8080/stats
```
2. Check the response headers for `Cache-Control` header with `max-age=300`
3. Make the same request again within 300 seconds and observe the response time (should be faster)
### 1.3 Test GET /demo Caching
1. Open `http://127.0.0.1:8080/demo` in a web browser
2. Check the network tab in the browser's developer tools for `Cache-Control` header with `max-age=3600`
3. Refresh the page within 3600 seconds and observe that resources are loaded from the browser cache
### 1.4 Test POST /event/search No-Caching
1. Make a POST request to `/event/search`:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{"geometry":{"type":"Point","coordinates":[2.3522, 48.8566]}}' http://127.0.0.1:8080/event/search
```
2. Check the response headers for `Cache-Control` header with `no-store, no-cache, must-revalidate, max-age=0`
3. Make the same request again and observe that the response is not served from cache (response time should be similar)
### 1.5 Test Error Response No-Caching
1. Make a request that will result in an error (e.g., invalid JSON):
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{invalid json}' http://127.0.0.1:8080/event/search
```
2. Check the response headers for `Cache-Control` header with `no-store, no-cache, must-revalidate, max-age=0`
## 2. Testing Rate Limiting
### 2.1 Test Global Rate Limit
1. Make 61 GET requests to `/event` within 60 seconds:
```bash
for i in {1..61}; do curl -v http://127.0.0.1:8080/event; sleep 1; done
```
2. Observe that the 61st request returns a `429 Too Many Requests` response with a `Retry-After` header
### 2.2 Test POST /event Rate Limit
1. Make 11 POST requests to `/event` within 60 seconds:
```bash
for i in {1..11}; do curl -v -X POST -H "Content-Type: application/json" -d '{"type":"Feature","geometry":{"type":"Point","coordinates":[2.3522, 48.8566]},"properties":{"type":"scheduled","what":"test.event","start":"2025-09-16T00:00:00","stop":"2025-09-16T23:59:59","label":"Test Event"}}' http://127.0.0.1:8080/event; sleep 5; done
```
2. Observe that the 11th request returns a `429 Too Many Requests` response with a `Retry-After` header
### 2.3 Test POST /event/search Rate Limit
1. Make 21 POST requests to `/event/search` within 60 seconds:
```bash
for i in {1..21}; do curl -v -X POST -H "Content-Type: application/json" -d '{"geometry":{"type":"Point","coordinates":[2.3522, 48.8566]}}' http://127.0.0.1:8080/event/search; sleep 2; done
```
2. Observe that the 21st request returns a `429 Too Many Requests` response with a `Retry-After` header
### 2.4 Test DELETE /event Rate Limit
1. Create a test event and note its ID:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{"type":"Feature","geometry":{"type":"Point","coordinates":[2.3522, 48.8566]},"properties":{"type":"scheduled","what":"test.event","start":"2025-09-16T00:00:00","stop":"2025-09-16T23:59:59","label":"Test Event"}}' http://127.0.0.1:8080/event
```
2. Make 6 DELETE requests to `/event/{id}` within 60 seconds:
```bash
for i in {1..6}; do curl -v -X DELETE http://127.0.0.1:8080/event/{id}; sleep 10; done
```
3. Observe that the 6th request returns a `429 Too Many Requests` response with a `Retry-After` header
## 3. Testing Search Functionality
### 3.1 Test Basic Search with Point Geometry
1. Make a POST request to `/event/search` with a Point geometry:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{"geometry":{"type":"Point","coordinates":[2.3522, 48.8566]}}' http://127.0.0.1:8080/event/search
```
2. Verify that the response contains events near the specified point
### 3.2 Test Search with Polygon Geometry
1. Make a POST request to `/event/search` with a Polygon geometry:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{"geometry":{"type":"Polygon","coordinates":[[[2.3, 48.8],[2.4, 48.8],[2.4, 48.9],[2.3, 48.9],[2.3, 48.8]]]}}' http://127.0.0.1:8080/event/search
```
2. Verify that the response contains events within the specified polygon
### 3.3 Test Search with Buffer
1. Make a POST request to `/event/search` with a Point geometry and a buffer:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{"geometry":{"type":"Point","coordinates":[2.3522, 48.8566]}}' "http://127.0.0.1:8080/event/search?buffer=5000"
```
2. Verify that the response contains events within 5km of the specified point
### 3.4 Test Search with Time Filter
1. Make a POST request to `/event/search` with a Point geometry and a time filter:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{"geometry":{"type":"Point","coordinates":[2.3522, 48.8566]}}' "http://127.0.0.1:8080/event/search?when=today"
```
2. Verify that the response contains events near the specified point that are active today
### 3.5 Test Search with Category Filter
1. Make a POST request to `/event/search` with a Point geometry and a category filter:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{"geometry":{"type":"Point","coordinates":[2.3522, 48.8566]}}' "http://127.0.0.1:8080/event/search?what=sport"
```
2. Verify that the response contains events near the specified point with a "what" value that starts with "sport"
### 3.6 Test Search with Type Filter
1. Make a POST request to `/event/search` with a Point geometry and a type filter:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{"geometry":{"type":"Point","coordinates":[2.3522, 48.8566]}}' "http://127.0.0.1:8080/event/search?type=scheduled"
```
2. Verify that the response contains events near the specified point with a "type" value of "scheduled"
### 3.7 Test Search with Limit
1. Make a POST request to `/event/search` with a Point geometry and a limit:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{"geometry":{"type":"Point","coordinates":[2.3522, 48.8566]}}' "http://127.0.0.1:8080/event/search?limit=5"
```
2. Verify that the response contains at most 5 events
### 3.8 Test Search with Full Geometry
1. Make a POST request to `/event/search` with a Point geometry and a request for full geometry:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{"geometry":{"type":"Point","coordinates":[2.3522, 48.8566]}}' "http://127.0.0.1:8080/event/search?geom=full"
```
2. Verify that the response contains events with their full geometry
### 3.9 Test Search with OSM ID
1. Make a POST request to `/event/search` with a Point geometry and an OSM ID filter:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{"geometry":{"type":"Point","coordinates":[2.3522, 48.8566]}}' "http://127.0.0.1:8080/event/search?where:osm=R12345"
```
2. Verify that the response contains events associated with the specified OSM ID
### 3.10 Test Search with Wikidata ID
1. Make a POST request to `/event/search` with a Point geometry and a Wikidata ID filter:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{"geometry":{"type":"Point","coordinates":[2.3522, 48.8566]}}' "http://127.0.0.1:8080/event/search?where:wikidata=Q90"
```
2. Verify that the response contains events associated with the specified Wikidata ID
## 4. Testing Error Handling
### 4.1 Test Invalid JSON
1. Make a POST request to `/event/search` with invalid JSON:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{invalid json}' http://127.0.0.1:8080/event/search
```
2. Verify that the response is a `400 Bad Request` with an error message
### 4.2 Test Missing Geometry
1. Make a POST request to `/event/search` without a geometry field:
```bash
curl -v -X POST -H "Content-Type: application/json" -d '{}' http://127.0.0.1:8080/event/search
```
2. Verify that the response is a `400 Bad Request` with an error message about the missing geometry field
## 5. Testing Demo Page
### 5.1 Test Demo Page with Real Events
1. Open `http://127.0.0.1:8080/demo` in a web browser
2. Verify that the map shows real events from the database
3. Click on an event marker and verify that the popup shows the event details
4. Verify that the map is centered on the events
### 5.2 Test Event Form
1. Open `http://127.0.0.1:8080/demo/add` in a web browser
2. Verify that the form has default values for the date fields (current date) and the map is centered on France
3. Fill out the form with test data and submit it
4. Verify that the event is created successfully
5. Go back to the demo page and verify that the new event is displayed on the map
## Conclusion
This test plan covers the key functionality of the caching, rate limiting, and search features implemented in the OpenEventDatabase API. By following these tests, you can verify that the implementations work as expected and meet the requirements specified in the issue description.