From 7ab6bae0766ffcb05347abdbdd5c22ff9b6e2247 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Mon, 27 Nov 2023 03:18:56 +0000 Subject: [PATCH] chore: fix flake in templates_test.go --- coderd/templates_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/coderd/templates_test.go b/coderd/templates_test.go index f8bb4e29da5cc..4a9ba47455286 100644 --- a/coderd/templates_test.go +++ b/coderd/templates_test.go @@ -525,6 +525,9 @@ func TestPatchTemplateMeta(t *testing.T) { user := coderdtest.CreateFirstUser(t, client) version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil) template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) + // It is unfortunate we need to sleep, but the test can fail if the + // updatedAt is too close together. + time.Sleep(time.Millisecond * 5) req := codersdk.UpdateTemplateMeta{ DeprecationMessage: ptr.Ref("APGL cannot deprecate"), @@ -550,6 +553,9 @@ func TestPatchTemplateMeta(t *testing.T) { client, tplAdmin := coderdtest.CreateAnotherUser(t, owner, user.OrganizationID, rbac.RoleTemplateAdmin()) version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil) template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) + // It is unfortunate we need to sleep, but the test can fail if the + // updatedAt is too close together. + time.Sleep(time.Millisecond * 5) ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) defer cancel() @@ -587,6 +593,10 @@ func TestPatchTemplateMeta(t *testing.T) { template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) { ctr.DefaultTTLMillis = ptr.Ref(24 * time.Hour.Milliseconds()) }) + // It is unfortunate we need to sleep, but the test can fail if the + // updatedAt is too close together. + time.Sleep(time.Millisecond * 5) + req := codersdk.UpdateTemplateMeta{ DefaultTTLMillis: 0, } @@ -618,6 +628,10 @@ func TestPatchTemplateMeta(t *testing.T) { template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) { ctr.DefaultTTLMillis = ptr.Ref(24 * time.Hour.Milliseconds()) }) + // It is unfortunate we need to sleep, but the test can fail if the + // updatedAt is too close together. + time.Sleep(time.Millisecond * 5) + req := codersdk.UpdateTemplateMeta{ DefaultTTLMillis: -1, }