From 9a241a2a4ffc2674a2134b51039bb4a281ad0960 Mon Sep 17 00:00:00 2001 From: Emil Hessman <248952+ceh@users.noreply.github.com> Date: Mon, 26 Oct 2020 07:45:30 +0100 Subject: [PATCH] Chore: Fix flaky sqlstore annotation test (#28527) --- pkg/services/sqlstore/annotation.go | 4 ++-- pkg/services/sqlstore/annotation_test.go | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/services/sqlstore/annotation.go b/pkg/services/sqlstore/annotation.go index 272f6f4e5f5..1e457d30dba 100644 --- a/pkg/services/sqlstore/annotation.go +++ b/pkg/services/sqlstore/annotation.go @@ -35,7 +35,7 @@ func (r *SqlAnnotationRepo) Save(item *annotations.Item) error { return inTransaction(func(sess *DBSession) error { tags := models.ParseTagPairs(item.Tags) item.Tags = models.JoinTagPairs(tags) - item.Created = time.Now().UnixNano() / int64(time.Millisecond) + item.Created = timeNow().UnixNano() / int64(time.Millisecond) item.Updated = item.Created if item.Epoch == 0 { item.Epoch = item.Created @@ -81,7 +81,7 @@ func (r *SqlAnnotationRepo) Update(item *annotations.Item) error { return errors.New("Annotation not found") } - existing.Updated = time.Now().UnixNano() / int64(time.Millisecond) + existing.Updated = timeNow().UnixNano() / int64(time.Millisecond) existing.Text = item.Text if item.Epoch != 0 { diff --git a/pkg/services/sqlstore/annotation_test.go b/pkg/services/sqlstore/annotation_test.go index 7487e82d732..c9c1d184888 100644 --- a/pkg/services/sqlstore/annotation_test.go +++ b/pkg/services/sqlstore/annotation_test.go @@ -11,6 +11,8 @@ import ( ) func TestAnnotations(t *testing.T) { + mockTimeNow() + defer resetTimeNow() InitTestDB(t) Convey("Testing annotation saving/loading", t, func() {