code refactor

This commit is contained in:
MaysWind
2023-03-26 23:53:52 +08:00
parent e17687f80d
commit 1d6dbf63c0
+5 -4
View File
@@ -54,7 +54,7 @@ func TestGenerateUuid_MultiType(t *testing.T) {
assert.Equal(t, uint32(expectedSeqId), actualSeqId)
}
func TestGenerateUuid_1000Times(t *testing.T) {
func TestGenerateUuid_2000TimesIn2Seconds(t *testing.T) {
generator, _ := NewInternalUuidGenerator(&settings.Config{UuidServerId: 2})
expectedUnixTime := time.Now().Unix()
@@ -79,17 +79,18 @@ func TestGenerateUuid_1000Times(t *testing.T) {
}
func TestGenerateUuid_1000000TimesConcurrent(t *testing.T) {
concurrentCount := 50
generator, _ := NewInternalUuidGenerator(&settings.Config{UuidServerId: 3})
var mutex sync.Mutex
var generatedIds sync.Map
var waitGroup sync.WaitGroup
for i := 0; i < 50; i++ {
for routineIndex := 0; routineIndex < concurrentCount; routineIndex++ {
go func() {
waitGroup.Add(1)
for j := 0; j < 40000; j++ {
if j%10000 == 0 { // echo server can only generate 500,000 (50 * 10000) uuids in one second
for cycle := 0; cycle < 40000; cycle++ {
if cycle%10000 == 0 { // each server can only generate 500,000 (50 * 10000) uuids in one second
time.Sleep(1000 * time.Millisecond)
}