test: fix data races

GitOrigin-RevId: 7dc520ddc926be30393d474734d37a5f58cc4851
This commit is contained in:
Philippe Gaultier 2025-12-04 17:10:19 +01:00 committed by ory-bot
parent 791b0d5987
commit 4014eeb08c
3 changed files with 80 additions and 17 deletions

View File

@ -35,11 +35,10 @@ func TestDriverDefault_Hooks(t *testing.T) {
t.Parallel()
ctx := context.Background()
_, reg := internal.NewVeryFastRegistryWithoutDB(t)
t.Run("type=verification", func(t *testing.T) {
t.Parallel()
// BEFORE hooks
_, reg := internal.NewVeryFastRegistryWithoutDB(t)
for _, tc := range []struct {
uc string
config map[string]any
@ -155,6 +154,7 @@ func TestDriverDefault_Hooks(t *testing.T) {
ctx := contextx.WithConfigValues(ctx, tc.config)
_, reg := internal.NewVeryFastRegistryWithoutDB(t)
h, err := reg.PreRecoveryHooks(ctx)
require.NoError(t, err)
@ -193,6 +193,7 @@ func TestDriverDefault_Hooks(t *testing.T) {
ctx := contextx.WithConfigValues(ctx, tc.config)
_, reg := internal.NewVeryFastRegistryWithoutDB(t)
h, err := reg.PostRecoveryHooks(ctx)
require.NoError(t, err)
@ -236,6 +237,7 @@ func TestDriverDefault_Hooks(t *testing.T) {
ctx := contextx.WithConfigValues(ctx, tc.config)
_, reg := internal.NewVeryFastRegistryWithoutDB(t)
h, err := reg.PreRegistrationHooks(ctx)
require.NoError(t, err)
@ -341,6 +343,7 @@ func TestDriverDefault_Hooks(t *testing.T) {
ctx := contextx.WithConfigValues(ctx, tc.config)
_, reg := internal.NewVeryFastRegistryWithoutDB(t)
h, err := reg.PostRegistrationPostPersistHooks(ctx, identity.CredentialsTypePassword)
require.NoError(t, err)
@ -382,6 +385,7 @@ func TestDriverDefault_Hooks(t *testing.T) {
ctx := contextx.WithConfigValues(ctx, tc.config)
_, reg := internal.NewVeryFastRegistryWithoutDB(t)
h, err := reg.PreLoginHooks(ctx)
require.NoError(t, err)
@ -483,6 +487,7 @@ func TestDriverDefault_Hooks(t *testing.T) {
ctx := contextx.WithConfigValues(ctx, tc.config)
_, reg := internal.NewVeryFastRegistryWithoutDB(t)
h, err := reg.PostLoginHooks(ctx, identity.CredentialsTypePassword)
require.NoError(t, err)
@ -524,6 +529,7 @@ func TestDriverDefault_Hooks(t *testing.T) {
ctx := contextx.WithConfigValues(ctx, tc.config)
_, reg := internal.NewVeryFastRegistryWithoutDB(t)
h, err := reg.PreSettingsHooks(ctx)
require.NoError(t, err)
@ -611,6 +617,7 @@ func TestDriverDefault_Hooks(t *testing.T) {
ctx := contextx.WithConfigValues(ctx, tc.config)
_, reg := internal.NewVeryFastRegistryWithoutDB(t)
h, err := reg.PostSettingsPostPersistHooks(ctx, "profile")
require.NoError(t, err)

View File

@ -140,27 +140,28 @@ func testDatabase(t *testing.T, db string, c *pop.Connection) {
})
wg := &sync.WaitGroup{}
d, err := driver.New(
context.Background(),
os.Stderr,
driver.WithConfigOptions(
configx.WithValues(map[string]any{
config.ViperKeyDSN: url,
config.ViperKeyPublicBaseURL: "https://www.ory.sh/",
config.ViperKeyIdentitySchemas: config.Schemas{{ID: "default", URL: "file://stub/default.schema.json"}},
config.ViperKeySecretsDefault: []string{"secret"},
}),
configx.SkipValidation(),
),
opts := driver.WithConfigOptions(
configx.WithValues(map[string]any{
config.ViperKeyDSN: url,
config.ViperKeyPublicBaseURL: "https://www.ory.sh/",
config.ViperKeyIdentitySchemas: config.Schemas{{ID: "default", URL: "file://stub/default.schema.json"}},
config.ViperKeySecretsDefault: []string{"secret"},
}),
configx.SkipValidation(),
)
require.NoError(t, err)
t.Run("case=identity", func(t *testing.T) {
wg.Add(1)
defer wg.Done()
t.Parallel()
d, err := driver.New(
context.Background(),
os.Stderr,
opts,
)
require.NoError(t, err)
ids, _, err := d.PrivilegedIdentityPool().ListIdentities(context.Background(), identity.ListIdentityParameters{Expand: identity.ExpandEverything, KeySetPagination: []keysetpagination.Option{keysetpagination.WithSize(1000)}})
require.NoError(t, err)
require.NotEmpty(t, ids)
@ -189,6 +190,13 @@ func testDatabase(t *testing.T, db string, c *pop.Connection) {
defer wg.Done()
t.Parallel()
d, err := driver.New(
context.Background(),
os.Stderr,
opts,
)
require.NoError(t, err)
ids, _, err := d.PrivilegedIdentityPool().ListIdentities(context.Background(), identity.ListIdentityParameters{Expand: identity.ExpandNothing, KeySetPagination: []keysetpagination.Option{keysetpagination.WithSize(1000)}})
require.NoError(t, err)
require.NotEmpty(t, ids)
@ -229,6 +237,13 @@ func testDatabase(t *testing.T, db string, c *pop.Connection) {
require.NoError(t, c.Select("id").All(&ids))
require.NotEmpty(t, ids)
d, err := driver.New(
context.Background(),
os.Stderr,
opts,
)
require.NoError(t, err)
var found []string
for _, id := range ids {
found = append(found, id.ID.String())
@ -249,6 +264,13 @@ func testDatabase(t *testing.T, db string, c *pop.Connection) {
require.NoError(t, c.Select("id").All(&ids))
require.NotEmpty(t, ids)
d, err := driver.New(
context.Background(),
os.Stderr,
opts,
)
require.NoError(t, err)
var found []string
for _, id := range ids {
found = append(found, id.ID.String())
@ -268,6 +290,13 @@ func testDatabase(t *testing.T, db string, c *pop.Connection) {
require.NoError(t, c.Select("id").All(&ids))
require.NotEmpty(t, ids)
d, err := driver.New(
context.Background(),
os.Stderr,
opts,
)
require.NoError(t, err)
var found []string
for _, id := range ids {
found = append(found, id.ID.String())
@ -287,6 +316,13 @@ func testDatabase(t *testing.T, db string, c *pop.Connection) {
require.NoError(t, c.Select("id").All(&ids))
require.NotEmpty(t, ids)
d, err := driver.New(
context.Background(),
os.Stderr,
opts,
)
require.NoError(t, err)
var found []string
for _, id := range ids {
found = append(found, id.ID.String())
@ -306,6 +342,13 @@ func testDatabase(t *testing.T, db string, c *pop.Connection) {
require.NoError(t, c.Select("id").All(&ids))
require.NotEmpty(t, ids)
d, err := driver.New(
context.Background(),
os.Stderr,
opts,
)
require.NoError(t, err)
var found []string
for _, id := range ids {
found = append(found, id.ID.String())
@ -325,6 +368,13 @@ func testDatabase(t *testing.T, db string, c *pop.Connection) {
require.NoError(t, c.Select("id").All(&ids))
require.NotEmpty(t, ids)
d, err := driver.New(
context.Background(),
os.Stderr,
opts,
)
require.NoError(t, err)
var found []string
for _, id := range ids {
found = append(found, id.ID.String())
@ -408,6 +458,13 @@ func testDatabase(t *testing.T, db string, c *pop.Connection) {
t.Parallel()
wg.Wait()
d, err := driver.New(
context.Background(),
os.Stderr,
opts,
)
require.NoError(t, err)
sr, err := d.SettingsFlowPersister().GetSettingsFlow(context.Background(), x.ParseUUID("a79bfcf1-68ae-49de-8b23-4f96921b8341"))
require.NoError(t, err)

View File

@ -135,7 +135,6 @@ func TestHandler(t *testing.T) {
for id, s := range schemas {
t.Run(fmt.Sprintf("case=get %s schema", id), func(t *testing.T) {
t.Parallel()
_, err := s.getRaw()
actual := getReq(t.Context(), t, fmt.Sprintf("/schemas/%s", url.PathEscape(id)), s.expectedHttpResponseCode)