Cosmetic improvements

This commit is contained in:
Taras Kushnir
2025-12-02 19:55:25 +01:00
parent 14fa5396e5
commit c2c3fa9156
4 changed files with 15 additions and 16 deletions

View File

@@ -72,7 +72,15 @@ func puzzleSuiteWithBackfillWait(t *testing.T, ctx context.Context, sitekey, dom
t.Errorf("Unexpected status code %d", resp.StatusCode)
}
time.Sleep(3 * authBackfillDelay)
for i := 0; i < 10; i++ {
time.Sleep(authBackfillDelay)
if _, err := store.Impl().GetCachedPropertyBySitekey(ctx, sitekey, nil); err != db.ErrCacheMiss {
break
} else {
slog.DebugContext(ctx, "Waiting for property to be cached", "attempt", i, common.ErrAttr(err))
}
}
resp, err = puzzleSuite(ctx, sitekey, domain)
if err != nil {

View File

@@ -62,7 +62,7 @@ func TestMain(m *testing.M) {
timeSeries = db.NewTimeSeries(clickhouse)
var err error
cache, err = db.NewMemoryCache[db.CacheKey, any]("default", 100, &struct{}{}, 1*time.Minute, 3*time.Minute, 30*time.Second)
cache, err = db.NewMemoryCache[db.CacheKey, any]("default", 1000, &struct{}{}, 1*time.Minute, 3*time.Minute, 30*time.Second)
if err != nil {
panic(err)
}

View File

@@ -22,15 +22,6 @@ import (
"github.com/PrivateCaptcha/PrivateCaptcha/pkg/puzzle"
)
func reverse(s string) string {
rune := []rune(s)
n := len(s)
for i := 0; i < n/2; i++ {
rune[i], rune[n-1-i] = rune[n-1-i], rune[i]
}
return string(rune)
}
func TestSerializeResponse(t *testing.T) {
v := VerifyResponseRecaptchaV3{
VerifyResponseRecaptchaV2: VerifyResponseRecaptchaV2{
@@ -185,12 +176,12 @@ func TestVerifyPuzzleWrongExpectedSitekey(t *testing.T) {
t.Skip("skipping integration test")
}
payload, apiKey, sitekey, err := setupVerifySuite(t.Name())
payload, apiKey, _, err := setupVerifySuite(t.Name())
if err != nil {
t.Fatal(err)
}
resp, err := verifySuite(payload, apiKey, reverse(sitekey))
resp, err := verifySuite(payload, apiKey, db.UUIDToSiteKey(*randomUUID()))
if err != nil {
t.Fatal(err)
}
@@ -225,12 +216,12 @@ func TestSiteVerifyWrongExpectedSitekey(t *testing.T) {
t.Skip("skipping integration test")
}
payload, apiKey, sitekey, err := setupVerifySuite(t.Name())
payload, apiKey, _, err := setupVerifySuite(t.Name())
if err != nil {
t.Fatal(err)
}
resp, err := siteVerifySuite(payload, apiKey, reverse(sitekey))
resp, err := siteVerifySuite(payload, apiKey, db.UUIDToSiteKey(*randomUUID()))
if err != nil {
t.Fatal(err)
}

View File

@@ -49,7 +49,7 @@ func TestMain(m *testing.M) {
panic(err)
}
cache, err = db.NewMemoryCache[db.CacheKey, any]("default", 100, &struct{}{}, 1*time.Minute, 3*time.Minute, 30*time.Second)
cache, err = db.NewMemoryCache[db.CacheKey, any]("default", 1000, &struct{}{}, 1*time.Minute, 3*time.Minute, 30*time.Second)
if err != nil {
panic(err)
}