Skip to content

Commit 1904584

Browse files
committed
changes from testing across environments
1 parent d2f6358 commit 1904584

2 files changed

Lines changed: 76 additions & 8 deletions

File tree

cache/__tests__/cache-metrics-worst-case.sh

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ declare -A ENDPOINT_DESCRIPTIONS
5353
# Array to store created object IDs for cleanup
5454
declare -a CREATED_IDS=()
5555

56+
# Associative array to store full created objects (to avoid unnecessary GET requests)
57+
declare -A CREATED_OBJECTS
58+
5659
# Report file - go up to repo root first
5760
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5861
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
@@ -350,12 +353,36 @@ create_test_object() {
350353

351354
if [ -n "$obj_id" ] && [ "$obj_id" != "null" ]; then
352355
CREATED_IDS+=("$obj_id")
356+
# Store the full object for later use (to avoid unnecessary GET requests)
357+
CREATED_OBJECTS["$obj_id"]="$response"
353358
sleep 1 # Allow DB and cache to process
354359
fi
355360

356361
echo "$obj_id"
357362
}
358363

364+
# Create test object and return the full object (not just ID)
365+
create_test_object_with_body() {
366+
local data=$1
367+
local description=${2:-"Creating test object"}
368+
369+
local response=$(curl -s -X POST "${API_BASE}/api/create" \
370+
-H "Content-Type: application/json" \
371+
-H "Authorization: Bearer ${AUTH_TOKEN}" \
372+
-d "$data" 2>/dev/null)
373+
374+
local obj_id=$(echo "$response" | jq -r '.["@id"]' 2>/dev/null)
375+
376+
if [ -n "$obj_id" ] && [ "$obj_id" != "null" ]; then
377+
CREATED_IDS+=("$obj_id")
378+
CREATED_OBJECTS["$obj_id"]="$response"
379+
sleep 1 # Allow DB and cache to process
380+
echo "$response"
381+
else
382+
echo ""
383+
fi
384+
}
385+
359386
################################################################################
360387
# Functionality Tests
361388
################################################################################
@@ -1827,7 +1854,8 @@ test_update_endpoint_empty() {
18271854

18281855
local NUM_ITERATIONS=50
18291856

1830-
local test_id=$(create_test_object '{"type":"UpdateTest","value":"original"}')
1857+
local test_obj=$(create_test_object_with_body '{"type":"UpdateTest","value":"original"}')
1858+
local test_id=$(echo "$test_obj" | jq -r '.["@id"]' 2>/dev/null)
18311859

18321860
if [ -z "$test_id" ] || [ "$test_id" == "null" ]; then
18331861
log_failure "Failed to create test object for update test"
@@ -1840,21 +1868,23 @@ test_update_endpoint_empty() {
18401868
declare -a empty_times=()
18411869
local empty_total=0
18421870
local empty_success=0
1871+
local full_object="$test_obj"
18431872

18441873
for i in $(seq 1 $NUM_ITERATIONS); do
1845-
local full_object=$(curl -s "$test_id" 2>/dev/null)
18461874
local update_body=$(echo "$full_object" | jq ". + {value: \"updated_$i\"}" 2>/dev/null)
18471875

18481876
local result=$(measure_endpoint "${API_BASE}/api/update" "PUT" \
18491877
"$update_body" \
18501878
"Update object" true)
18511879
local time=$(echo "$result" | cut -d'|' -f1)
18521880
local code=$(echo "$result" | cut -d'|' -f2)
1881+
local response=$(echo "$result" | cut -d'|' -f3)
18531882

18541883
if [ "$code" == "200" ]; then
18551884
empty_times+=($time)
18561885
empty_total=$((empty_total + time))
18571886
empty_success=$((empty_success + 1))
1887+
full_object="$response"
18581888
fi
18591889

18601890
# Progress indicator
@@ -1887,7 +1917,8 @@ test_update_endpoint_full() {
18871917

18881918
local NUM_ITERATIONS=50
18891919

1890-
local test_id=$(create_test_object '{"type":"WORST_CASE_WRITE_UNIQUE_99999","value":"original"}')
1920+
local test_obj=$(create_test_object_with_body '{"type":"WORST_CASE_WRITE_UNIQUE_99999","value":"original"}')
1921+
local test_id=$(echo "$test_obj" | jq -r '.["@id"]' 2>/dev/null)
18911922

18921923
if [ -z "$test_id" ] || [ "$test_id" == "null" ]; then
18931924
log_failure "Failed to create test object for update test"
@@ -1900,21 +1931,23 @@ test_update_endpoint_full() {
19001931
declare -a full_times=()
19011932
local full_total=0
19021933
local full_success=0
1934+
local full_object="$test_obj"
19031935

19041936
for i in $(seq 1 $NUM_ITERATIONS); do
1905-
local full_object=$(curl -s "$test_id" 2>/dev/null)
19061937
local update_body=$(echo "$full_object" | jq ". + {value: \"updated_full_$i\"}" 2>/dev/null)
19071938

19081939
local result=$(measure_endpoint "${API_BASE}/api/update" "PUT" \
19091940
"$update_body" \
19101941
"Update object" true)
19111942
local time=$(echo "$result" | cut -d'|' -f1)
19121943
local code=$(echo "$result" | cut -d'|' -f2)
1944+
local response=$(echo "$result" | cut -d'|' -f3)
19131945

19141946
if [ "$code" == "200" ]; then
19151947
full_times+=($time)
19161948
full_total=$((full_total + time))
19171949
full_success=$((full_success + 1))
1950+
full_object="$response"
19181951
fi
19191952

19201953
# Progress indicator

cache/__tests__/cache-metrics.sh

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ declare -A ENDPOINT_DESCRIPTIONS
5252
# Array to store created object IDs for cleanup
5353
declare -a CREATED_IDS=()
5454

55+
# Associative array to store full created objects (to avoid unnecessary GET requests)
56+
declare -A CREATED_OBJECTS
57+
5558
# Report file - go up to repo root first
5659
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5760
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
@@ -368,12 +371,36 @@ create_test_object() {
368371

369372
if [ -n "$obj_id" ] && [ "$obj_id" != "null" ]; then
370373
CREATED_IDS+=("$obj_id")
374+
# Store the full object for later use (to avoid unnecessary GET requests)
375+
CREATED_OBJECTS["$obj_id"]="$response"
371376
sleep 1 # Allow DB and cache to process
372377
fi
373378

374379
echo "$obj_id"
375380
}
376381

382+
# Create test object and return the full object (not just ID)
383+
create_test_object_with_body() {
384+
local data=$1
385+
local description=${2:-"Creating test object"}
386+
387+
local response=$(curl -s -X POST "${API_BASE}/api/create" \
388+
-H "Content-Type: application/json" \
389+
-H "Authorization: Bearer ${AUTH_TOKEN}" \
390+
-d "$data" 2>/dev/null)
391+
392+
local obj_id=$(echo "$response" | jq -r '.["@id"]' 2>/dev/null)
393+
394+
if [ -n "$obj_id" ] && [ "$obj_id" != "null" ]; then
395+
CREATED_IDS+=("$obj_id")
396+
CREATED_OBJECTS["$obj_id"]="$response"
397+
sleep 1 # Allow DB and cache to process
398+
echo "$response"
399+
else
400+
echo ""
401+
fi
402+
}
403+
377404
################################################################################
378405
# Functionality Tests
379406
################################################################################
@@ -1844,7 +1871,8 @@ test_update_endpoint_empty() {
18441871

18451872
local NUM_ITERATIONS=50
18461873

1847-
local test_id=$(create_test_object '{"type":"UpdateTest","value":"original"}')
1874+
local test_obj=$(create_test_object_with_body '{"type":"UpdateTest","value":"original"}')
1875+
local test_id=$(echo "$test_obj" | jq -r '.["@id"]' 2>/dev/null)
18481876

18491877
if [ -z "$test_id" ] || [ "$test_id" == "null" ]; then
18501878
log_failure "Failed to create test object for update test"
@@ -1857,21 +1885,24 @@ test_update_endpoint_empty() {
18571885
declare -a empty_times=()
18581886
local empty_total=0
18591887
local empty_success=0
1888+
local full_object="$test_obj"
18601889

18611890
for i in $(seq 1 $NUM_ITERATIONS); do
1862-
local full_object=$(curl -s "$test_id" 2>/dev/null)
18631891
local update_body=$(echo "$full_object" | jq ". + {value: \"updated_$i\"}" 2>/dev/null)
18641892

18651893
local result=$(measure_endpoint "${API_BASE}/api/update" "PUT" \
18661894
"$update_body" \
18671895
"Update object" true)
18681896
local time=$(echo "$result" | cut -d'|' -f1)
18691897
local code=$(echo "$result" | cut -d'|' -f2)
1898+
local response=$(echo "$result" | cut -d'|' -f3-)
18701899

18711900
if [ "$code" == "200" ]; then
18721901
empty_times+=($time)
18731902
empty_total=$((empty_total + time))
18741903
empty_success=$((empty_success + 1))
1904+
# Update full_object with the response for next iteration
1905+
full_object="$response"
18751906
fi
18761907

18771908
# Progress indicator
@@ -1904,7 +1935,8 @@ test_update_endpoint_full() {
19041935

19051936
local NUM_ITERATIONS=50
19061937

1907-
local test_id=$(create_test_object '{"type":"UpdateTest","value":"original"}')
1938+
local test_obj=$(create_test_object_with_body '{"type":"UpdateTest","value":"original"}')
1939+
local test_id=$(echo "$test_obj" | jq -r '.["@id"]' 2>/dev/null)
19081940

19091941
if [ -z "$test_id" ] || [ "$test_id" == "null" ]; then
19101942
log_failure "Failed to create test object for update test"
@@ -1916,21 +1948,24 @@ test_update_endpoint_full() {
19161948
declare -a full_times=()
19171949
local full_total=0
19181950
local full_success=0
1951+
local full_object="$test_obj"
19191952

19201953
for i in $(seq 1 $NUM_ITERATIONS); do
1921-
local full_object=$(curl -s "$test_id" 2>/dev/null)
19221954
local update_body=$(echo "$full_object" | jq ". + {value: \"updated_full_$i\"}" 2>/dev/null)
19231955

19241956
local result=$(measure_endpoint "${API_BASE}/api/update" "PUT" \
19251957
"$update_body" \
19261958
"Update object" true)
19271959
local time=$(echo "$result" | cut -d'|' -f1)
19281960
local code=$(echo "$result" | cut -d'|' -f2)
1961+
local response=$(echo "$result" | cut -d'|' -f3-)
19291962

19301963
if [ "$code" == "200" ]; then
19311964
full_times+=($time)
19321965
full_total=$((full_total + time))
19331966
full_success=$((full_success + 1))
1967+
# Update full_object with the response for next iteration
1968+
full_object="$response"
19341969
fi
19351970

19361971
# Progress indicator

0 commit comments

Comments
 (0)