Add production hardening: monitoring, backups, caching, and high-traffic resilience
- Recovery middleware (no more crash-on-panic), request metrics/monitoring store + admin API, in-memory TTL caching for read-heavy option/question/ category lookups, gzip + rate-limiting middleware, sanitized chat message encoding, and pg_dump-based database backups with an admin API. - Fix N+1 queries in the discover feed, candidate detail, and match list endpoints by batching selection/photo/user/last-message lookups into single queries instead of one-per-item loops. - Tune DB connection pooling and add HTTP server timeouts + graceful shutdown so the API degrades gracefully instead of falling over under load. - Fix a null (vs empty array) JSON response for candidates/matches without photos or interests, which crashed the web app's swipe card.
This commit is contained in:
Vendored
+62
@@ -0,0 +1,62 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestTTLCache_SetGet(t *testing.T) {
|
||||
c := New[string, int](time.Minute)
|
||||
c.Set("a", 42)
|
||||
|
||||
v, ok := c.Get("a")
|
||||
if !ok || v != 42 {
|
||||
t.Fatalf("expected (42, true), got (%d, %v)", v, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTTLCache_MissingKey(t *testing.T) {
|
||||
c := New[string, int](time.Minute)
|
||||
if _, ok := c.Get("missing"); ok {
|
||||
t.Fatal("expected miss for key that was never set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTTLCache_Expiry(t *testing.T) {
|
||||
c := New[string, int](10 * time.Millisecond)
|
||||
c.Set("a", 1)
|
||||
|
||||
if _, ok := c.Get("a"); !ok {
|
||||
t.Fatal("expected hit immediately after Set")
|
||||
}
|
||||
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
|
||||
if _, ok := c.Get("a"); ok {
|
||||
t.Fatal("expected miss after TTL expired")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTTLCache_Delete(t *testing.T) {
|
||||
c := New[string, int](time.Minute)
|
||||
c.Set("a", 1)
|
||||
c.Delete("a")
|
||||
|
||||
if _, ok := c.Get("a"); ok {
|
||||
t.Fatal("expected miss after Delete")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTTLCache_Clear(t *testing.T) {
|
||||
c := New[string, int](time.Minute)
|
||||
c.Set("a", 1)
|
||||
c.Set("b", 2)
|
||||
c.Clear()
|
||||
|
||||
if _, ok := c.Get("a"); ok {
|
||||
t.Fatal("expected miss for 'a' after Clear")
|
||||
}
|
||||
if _, ok := c.Get("b"); ok {
|
||||
t.Fatal("expected miss for 'b' after Clear")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user