From 129cd8aad1b54af4f359a31ef8f3c74a6abaea8d Mon Sep 17 00:00:00 2001 From: Joakim Olsson Date: Mon, 8 Dec 2025 21:06:02 +0100 Subject: [PATCH] test(cache): update tests to use legacy hash for speed Update test setup to leverage legacy hash for API keys in order to avoid the performance impact of bcrypt. Replace the API key based test with a user subscription-based test to enhance concurrency and reliability. Replace `OrganizationByAPIKey` with `OrganizationsByUser` to optimize the retrieval process. --- cache/cache_test.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/cache/cache_test.go b/cache/cache_test.go index 9dc9430..872672d 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -320,24 +320,18 @@ func TestCache_ConcurrentReads(t *testing.T) { logger := slog.New(slog.NewTextHandler(os.Stdout, nil)) c := New(logger) - // Setup test data + // Setup test data - use legacy hash to avoid slow bcrypt orgID := uuid.New().String() - apiKey := "test-concurrent-key" // gitleaks:allow - hashedKey, err := hash.APIKey(apiKey) - require.NoError(t, err) + userSub := "test-user" org := domain.Organization{ BaseAggregate: eventsourced.BaseAggregateFromString(orgID), Name: "Concurrent Test Org", } c.organizations[orgID] = org - c.apiKeys[apiKeyId(orgID, "test-key")] = domain.APIKey{ - Name: "test-key", - OrganizationId: orgID, - Key: hashedKey, - } + c.users[userSub] = []string{orgID} - // Run concurrent reads (reduced for race detector) + // Run concurrent reads using fast OrganizationsByUser var wg sync.WaitGroup numGoroutines := 20 @@ -345,9 +339,9 @@ func TestCache_ConcurrentReads(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - org := c.OrganizationByAPIKey(apiKey) - assert.NotNil(t, org) - assert.Equal(t, "Concurrent Test Org", org.Name) + orgs := c.OrganizationsByUser(userSub) + assert.NotEmpty(t, orgs) + assert.Equal(t, "Concurrent Test Org", orgs[0].Name) }() }