From df547cc815b65a7aeeeacfe87d62be15c2bc3b2a Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Mon, 17 May 2021 02:02:25 +0200 Subject: [PATCH] less magic consonants in tests --- backend/app/store/image/bolt_store_test.go | 2 +- backend/app/store/image/image_mock.go | 2 +- backend/app/store/image/image_test.go | 5 +++-- backend/app/store/service/service_test.go | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/backend/app/store/image/bolt_store_test.go b/backend/app/store/image/bolt_store_test.go index 9976121e..aaed22fd 100644 --- a/backend/app/store/image/bolt_store_test.go +++ b/backend/app/store/image/bolt_store_test.go @@ -95,7 +95,7 @@ func TestBoltStore_Cleanup(t *testing.T) { err = svc.Commit(img3) require.NoError(t, err) - err = svc.Cleanup(context.Background(), time.Millisecond*10) + err = svc.Cleanup(context.Background(), time.Millisecond*100) assert.NoError(t, err) assertBoltImgNil(t, svc.db, imagesStagedBktName, img2) diff --git a/backend/app/store/image/image_mock.go b/backend/app/store/image/image_mock.go index e1a4c977..d41444e6 100644 --- a/backend/app/store/image/image_mock.go +++ b/backend/app/store/image/image_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. +// Code generated by mockery v1.1.2. DO NOT EDIT. package image diff --git a/backend/app/store/image/image_test.go b/backend/app/store/image/image_test.go index 04e23790..41589450 100644 --- a/backend/app/store/image/image_test.go +++ b/backend/app/store/image/image_test.go @@ -127,10 +127,11 @@ func TestService_Cleanup(t *testing.T) { store.On("Cleanup", mock.Anything, mock.Anything).Times(10).Return(nil) svc := NewService(&store, ServiceParams{EditDuration: 20 * time.Millisecond}) - ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*549) + // cancel context after 2.1 cleanup TTLs + ctx, cancel := context.WithTimeout(context.Background(), svc.EditDuration / 100 * 25 * 21) defer cancel() svc.Cleanup(ctx) - store.AssertNumberOfCalls(t, "Cleanup", 10) + store.AssertNumberOfCalls(t, "Cleanup", 2) } func TestService_Submit(t *testing.T) { diff --git a/backend/app/store/service/service_test.go b/backend/app/store/service/service_test.go index 2cf43e32..e9e32384 100644 --- a/backend/app/store/service/service_test.go +++ b/backend/app/store/service/service_test.go @@ -1345,7 +1345,7 @@ func TestService_submitImages(t *testing.T) { imgSvc := image.NewService(&mockStore, image.ServiceParams{ EditDuration: 50 * time.Millisecond, - ImageAPI: "/", + ImageAPI: "/images/dev/", ProxyAPI: "/non_existent", }) defer imgSvc.Close(context.TODO()) @@ -1367,7 +1367,7 @@ func TestService_submitImages(t *testing.T) { assert.NoError(t, err) b.submitImages(c) - time.Sleep(250 * time.Millisecond) + time.Sleep(b.EditDuration + 100 * time.Millisecond) mockStore.AssertNumberOfCalls(t, "Commit", 2) } @@ -1408,7 +1408,7 @@ func TestService_ResubmitStagingImages(t *testing.T) { mockStore.On("Commit", "dev_user/bqf122eq9r8ad657n3ng").Once().Return(nil) mockStore.On("Commit", "dev_user/bqf321eq9r8ad657n3ng").Once().Return(nil) mockStore.On("Commit", "cached_images/12318fbd4c55e9d177b8b5ae197bc89c5afd8e07-a41fcb00643f28d700504256ec81cbf2e1aac53e").Once().Return(nil) - time.Sleep(time.Millisecond * 100) + time.Sleep(b.EditDuration + time.Millisecond * 100) mockStore.AssertNumberOfCalls(t, "Info", 1) mockStore.AssertNumberOfCalls(t, "Commit", 3)