From 12d5837526103542688f0c22fdcebb6d7d4f8353 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 23 Apr 2023 21:48:04 +0800 Subject: [PATCH] modify unit test case fail cause message --- pkg/uuid/internal_generator_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/uuid/internal_generator_test.go b/pkg/uuid/internal_generator_test.go index 88f87485..503093a8 100644 --- a/pkg/uuid/internal_generator_test.go +++ b/pkg/uuid/internal_generator_test.go @@ -86,7 +86,7 @@ func TestGenerateUuid_1000000TimesConcurrent(t *testing.T) { var waitGroup sync.WaitGroup for routineIndex := 0; routineIndex < concurrentCount; routineIndex++ { - go func() { + go func(currentRoutineIndex int) { waitGroup.Add(1) for cycle := 0; cycle < 40000; cycle++ { @@ -105,18 +105,18 @@ func TestGenerateUuid_1000000TimesConcurrent(t *testing.T) { } if uuidInfo.SequentialId == 0 { - if existedUnixTime, exists := generatedIds.Load(uuid); exists { + if existedRoutineIndex, exists := generatedIds.Load(uuid); exists { mutex.Lock() - assert.Fail(t, fmt.Sprintf("uuid \"%d\" conflicts, seq id is %d, existed unixtime is %d, current unix time is %d", uuid, uuidInfo.SequentialId, existedUnixTime, uuidInfo.UnixTime)) + assert.Fail(t, fmt.Sprintf("uuid \"%d\" conflicts, unix time is %d, seq id is %d, existed routine index is %d, current routine index is %d", uuid, uuidInfo.UnixTime, uuidInfo.SequentialId, existedRoutineIndex, currentRoutineIndex)) mutex.Unlock() } - generatedIds.Store(uuid, uuidInfo.UnixTime) + generatedIds.Store(uuid, currentRoutineIndex) } } waitGroup.Done() - }() + }(routineIndex) } waitGroup.Wait() @@ -208,7 +208,7 @@ func TestGenerateUuids_1000000TimesConcurrent(t *testing.T) { var waitGroup sync.WaitGroup for routineIndex := 0; routineIndex < concurrentCount; routineIndex++ { - go func() { + go func(currentRoutineIndex int) { waitGroup.Add(1) for cycle := 0; cycle < 400; cycle++ { @@ -228,18 +228,18 @@ func TestGenerateUuids_1000000TimesConcurrent(t *testing.T) { mutex.Unlock() } - if existedUnixTime, exists := generatedIds.Load(uuids[i]); exists { + if existedRoutineIndex, exists := generatedIds.Load(uuids[i]); exists { mutex.Lock() - assert.Fail(t, fmt.Sprintf("uuid \"%d\" conflicts, seq id is %d, existed unixtime is %d, current unix time is %d", uuids[i], uuidInfo.SequentialId, existedUnixTime, uuidInfo.UnixTime)) + assert.Fail(t, fmt.Sprintf("uuid \"%d\" conflicts, unix time is %d, seq id is %d, existed routine index is %d, current routine index is %d", uuids[i], uuidInfo.UnixTime, uuidInfo.SequentialId, existedRoutineIndex, currentRoutineIndex)) mutex.Unlock() } - generatedIds.Store(uuids[i], uuidInfo.UnixTime) + generatedIds.Store(uuids[i], currentRoutineIndex) } } waitGroup.Done() - }() + }(routineIndex) } waitGroup.Wait()