From 7c8ecc2ebe2d077a2ab1d3132f5a11a6cf598df4 Mon Sep 17 00:00:00 2001 From: mikestefanello Date: Tue, 17 May 2022 08:57:43 -0400 Subject: [PATCH] Fixed potential test failures due to timing. --- context/context_test.go | 2 +- services/auth_test.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/context/context_test.go b/context/context_test.go index 77abb6a..6a5841d 100644 --- a/context/context_test.go +++ b/context/context_test.go @@ -16,7 +16,7 @@ func TestIsCanceled(t *testing.T) { assert.True(t, IsCanceledError(ctx.Err())) ctx, cancel = context.WithTimeout(context.Background(), time.Microsecond) - time.Sleep(time.Microsecond * 2) + time.Sleep(time.Microsecond * 5) cancel() assert.False(t, IsCanceledError(ctx.Err())) diff --git a/services/auth_test.go b/services/auth_test.go index 1f58b77..4028073 100644 --- a/services/auth_test.go +++ b/services/auth_test.go @@ -70,12 +70,13 @@ func TestAuthClient_GetValidPasswordToken(t *testing.T) { assert.Equal(t, pt.ID, pt2.ID) // Expire the token by pushing the date far enough back - _, err = c.ORM.PasswordToken. + count, err := c.ORM.PasswordToken. Update(). - SetCreatedAt(time.Now().Add(-(c.Config.App.PasswordToken.Expiration + 3600))). + SetCreatedAt(time.Now().Add(-(c.Config.App.PasswordToken.Expiration + time.Hour))). Where(passwordtoken.ID(pt.ID)). Save(context.Background()) require.NoError(t, err) + require.Equal(t, 1, count) // Expired tokens should not be valid _, err = c.Auth.GetValidPasswordToken(ctx, usr.ID, pt.ID, token)