Merge branch 'test-cache-legacy-hash-optimizations' into 'main'

test(cache): update tests to use legacy hash for speed

See merge request unboundsoftware/schemas!652
This commit was merged in pull request #656.
This commit is contained in:
2025-12-08 21:31:02 +01:00
+7 -13
View File
@@ -320,24 +320,18 @@ func TestCache_ConcurrentReads(t *testing.T) {
logger := slog.New(slog.NewTextHandler(os.Stdout, nil)) logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
c := New(logger) c := New(logger)
// Setup test data // Setup test data - use legacy hash to avoid slow bcrypt
orgID := uuid.New().String() orgID := uuid.New().String()
apiKey := "test-concurrent-key" // gitleaks:allow userSub := "test-user"
hashedKey, err := hash.APIKey(apiKey)
require.NoError(t, err)
org := domain.Organization{ org := domain.Organization{
BaseAggregate: eventsourced.BaseAggregateFromString(orgID), BaseAggregate: eventsourced.BaseAggregateFromString(orgID),
Name: "Concurrent Test Org", Name: "Concurrent Test Org",
} }
c.organizations[orgID] = org c.organizations[orgID] = org
c.apiKeys[apiKeyId(orgID, "test-key")] = domain.APIKey{ c.users[userSub] = []string{orgID}
Name: "test-key",
OrganizationId: orgID,
Key: hashedKey,
}
// Run concurrent reads (reduced for race detector) // Run concurrent reads using fast OrganizationsByUser
var wg sync.WaitGroup var wg sync.WaitGroup
numGoroutines := 20 numGoroutines := 20
@@ -345,9 +339,9 @@ func TestCache_ConcurrentReads(t *testing.T) {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
org := c.OrganizationByAPIKey(apiKey) orgs := c.OrganizationsByUser(userSub)
assert.NotNil(t, org) assert.NotEmpty(t, orgs)
assert.Equal(t, "Concurrent Test Org", org.Name) assert.Equal(t, "Concurrent Test Org", orgs[0].Name)
}() }()
} }