From be720f1ac8d2811a613260fc247076191ca3ac14 Mon Sep 17 00:00:00 2001 From: "guzel.gatina" Date: Thu, 17 Oct 2024 10:30:29 +0300 Subject: [PATCH] replace map on testPhaseObjects to sync.Map --- init.go | 7 ++++--- test_phase_container.go | 17 +++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/init.go b/init.go index 7b57377..3c9f618 100644 --- a/init.go +++ b/init.go @@ -1,8 +1,9 @@ package allure import ( - "github.com/jtolds/gls" "sync" + + "github.com/jtolds/gls" ) var ( @@ -11,7 +12,7 @@ var ( resultsPath string createFolderOnce sync.Once copyEnvFileOnce sync.Once - testPhaseObjects map[string]*testPhaseContainer + testPhaseObjects sync.Map ) const ( @@ -25,5 +26,5 @@ const ( func init() { ctxMgr = gls.NewContextManager() - testPhaseObjects = make(map[string]*testPhaseContainer) + testPhaseObjects = sync.Map{} } diff --git a/test_phase_container.go b/test_phase_container.go index 023e438..73f1409 100644 --- a/test_phase_container.go +++ b/test_phase_container.go @@ -112,18 +112,11 @@ func (sc *subContainer) getStatus() string { } func getCurrentTestPhaseObject(t *testing.T) *testPhaseContainer { - var currentPhaseObject *testPhaseContainer - if phaseContainer, ok := testPhaseObjects[t.Name()]; ok { - currentPhaseObject = phaseContainer - } else { - currentPhaseObject = &testPhaseContainer{ - Befores: make([]*container, 0), - Afters: make([]*container, 0), - } - testPhaseObjects[t.Name()] = currentPhaseObject - } - - return currentPhaseObject + phaseContainer, _ := testPhaseObjects.LoadOrStore(t.Name(), &testPhaseContainer{ + Befores: make([]*container, 0), + Afters: make([]*container, 0), + }) + return phaseContainer.(*testPhaseContainer) } func (c container) writeResultsFile() error {