From 46fc51275e483a084636587b623920517a55010c Mon Sep 17 00:00:00 2001 From: yankomissarov Date: Tue, 25 Mar 2025 17:30:29 +0300 Subject: [PATCH] MSP-5093 remove global varibale --- assembly/assembly.go | 3 ++- assembly/locator.go | 15 ++++++++------- tests/audit_test.go | 3 ++- tests/auth_test.go | 2 +- tests/customization_test.go | 3 ++- tests/inactive_test.go | 12 ++++++------ tests/secure_test.go | 2 +- tests/user_test.go | 2 +- 8 files changed, 23 insertions(+), 19 deletions(-) diff --git a/assembly/assembly.go b/assembly/assembly.go index 0af5de0..5802fd1 100644 --- a/assembly/assembly.go +++ b/assembly/assembly.go @@ -2,6 +2,7 @@ package assembly import ( "context" + "time" "github.com/pkg/errors" "github.com/txix-open/isp-kit/app" @@ -70,7 +71,7 @@ func (a *Assembly) ReceiveConfig(ctx context.Context, remoteConfig []byte) error return nil, errors.WithMessage(err, "new repository") } return repo, nil - }, newCfg) + }, newCfg, time.Minute) a.server.Upgrade(config.Handler) diff --git a/assembly/locator.go b/assembly/locator.go index b9d23b8..df59f07 100644 --- a/assembly/locator.go +++ b/assembly/locator.go @@ -22,10 +22,6 @@ import ( "msp-admin-service/transaction" ) -var ( - JobPollInterval = 1 * time.Minute //nolint:gochecknoglobals -) - type DB interface { db.DB db.Transactional @@ -51,7 +47,12 @@ type Config struct { } //nolint:funlen -func (l Locator) Config(ctx context.Context, ldapRepoSupplier ldap.RepoSupplier, cfg conf.Remote) Config { +func (l Locator) Config( + ctx context.Context, + ldapRepoSupplier ldap.RepoSupplier, + cfg conf.Remote, + jobPollInterval time.Duration, +) Config { sudirRepo := repository.NewSudir(l.httpCli, cfg.SudirAuth) roleRepo := repository.NewRole(l.db) userRepo := repository.NewUser(l.db) @@ -129,12 +130,12 @@ func (l Locator) Config(ctx context.Context, ldapRepoSupplier ldap.RepoSupplier, BgJobCfg: []bgjobx.WorkerConfig{{ Queue: delete_old_audit_worker.QueueName, Concurrency: 1, - PollInterval: JobPollInterval, + PollInterval: jobPollInterval, Handle: deleteOldAuditWorker, }, { Queue: inactive_worker.QueueName, Concurrency: 1, - PollInterval: JobPollInterval, + PollInterval: jobPollInterval, Handle: inactiveBlocker, }}, } diff --git a/tests/audit_test.go b/tests/audit_test.go index 4194709..05dd51a 100644 --- a/tests/audit_test.go +++ b/tests/audit_test.go @@ -3,6 +3,7 @@ package tests_test import ( "context" "testing" + "time" "github.com/stretchr/testify/suite" "github.com/txix-open/isp-kit/dbx" @@ -65,7 +66,7 @@ func (t *AuditSuite) SetupTest() { }, } cfg := assembly.NewLocator(testInstance.Logger(), httpcli.New(), t.db). - Config(context.Background(), emptyLdap, remote) + Config(context.Background(), emptyLdap, remote, time.Minute) server, apiCli := grpct.TestServer(testInstance, cfg.Handler) t.grpcCli = apiCli diff --git a/tests/auth_test.go b/tests/auth_test.go index a035c6a..6442802 100644 --- a/tests/auth_test.go +++ b/tests/auth_test.go @@ -65,7 +65,7 @@ func (s *AuthTestSuite) SetupTest() { }, } cfg := assembly.NewLocator(testInstance.Logger(), s.httpCli, s.db). - Config(context.Background(), emptyLdap, remote) + Config(context.Background(), emptyLdap, remote, time.Minute) server, apiCli := grpct.TestServer(testInstance, cfg.Handler) s.grpcCli = apiCli diff --git a/tests/customization_test.go b/tests/customization_test.go index b10746a..700c907 100644 --- a/tests/customization_test.go +++ b/tests/customization_test.go @@ -3,6 +3,7 @@ package tests_test import ( "context" "testing" + "time" "github.com/stretchr/testify/suite" "github.com/txix-open/isp-kit/dbx" @@ -39,7 +40,7 @@ func (s *CustomizationTestSuite) SetupTest() { ExpireSec: 0, } cfg := assembly.NewLocator(testInstance.Logger(), nil, s.db). - Config(context.Background(), emptyLdap, remote) + Config(context.Background(), emptyLdap, remote, time.Minute) server, apiCli := grpct.TestServer(testInstance, cfg.Handler) s.grpcCli = apiCli diff --git a/tests/inactive_test.go b/tests/inactive_test.go index f96f582..b705621 100644 --- a/tests/inactive_test.go +++ b/tests/inactive_test.go @@ -1,6 +1,7 @@ package tests_test import ( + "msp-admin-service/service/inactive_worker" "testing" "time" @@ -12,7 +13,6 @@ import ( "msp-admin-service/conf" "msp-admin-service/entity" "msp-admin-service/repository" - "msp-admin-service/service/inactive_worker" ) func TestInactiveWorker(t *testing.T) { @@ -42,14 +42,14 @@ func TestInactiveWorker(t *testing.T) { Config(t.Context(), emptyLdap, conf.Remote{ BlockInactiveWorker: conf.BlockInactiveWorker{ DaysThreshold: 1, - RunIntervalInMinutes: 60, + RunIntervalInMinutes: 1, }, - }) + }, 500*time.Millisecond) + bgjobCli := bgjobx.NewClient(db, test.Logger()) - assembly.JobPollInterval = 300 * time.Millisecond - err := bgjobCli.Upgrade(t.Context(), config.BgJobCfg) + err := inactive_worker.EnqueueSeedJob(t.Context(), bgjobCli) require.NoError(err) - err = inactive_worker.EnqueueSeedJob(t.Context(), bgjobCli) + err = bgjobCli.Upgrade(t.Context(), config.BgJobCfg) require.NoError(err) time.Sleep(5 * time.Second) diff --git a/tests/secure_test.go b/tests/secure_test.go index 56a3c5e..1fe2484 100644 --- a/tests/secure_test.go +++ b/tests/secure_test.go @@ -40,7 +40,7 @@ func (s *SecureSuite) SetupTest() { ExpireSec: 3600, } cfg := assembly.NewLocator(s.test.Logger(), httpCli, s.db). - Config(context.Background(), emptyLdap, remote) + Config(context.Background(), emptyLdap, remote, time.Minute) server, apiCli := grpct.TestServer(s.test, cfg.Handler) s.test.T().Cleanup(func() { diff --git a/tests/user_test.go b/tests/user_test.go index 2fd7ca7..ecb2c03 100644 --- a/tests/user_test.go +++ b/tests/user_test.go @@ -54,7 +54,7 @@ func (s *UserTestSuite) SetupTest() { ExpireSec: 0, } cfg := assembly.NewLocator(testInstance.Logger(), s.httpCli, s.db). - Config(context.Background(), emptyLdap, remote) + Config(context.Background(), emptyLdap, remote, time.Minute) server, apiCli := grpct.TestServer(testInstance, cfg.Handler) s.grpcCli = apiCli