mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 09:44:26 +08:00
code refactor
This commit is contained in:
@@ -54,7 +54,7 @@ func TestGenerateUuid_MultiType(t *testing.T) {
|
|||||||
assert.Equal(t, uint32(expectedSeqId), actualSeqId)
|
assert.Equal(t, uint32(expectedSeqId), actualSeqId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateUuid_1000Times(t *testing.T) {
|
func TestGenerateUuid_2000TimesIn2Seconds(t *testing.T) {
|
||||||
generator, _ := NewInternalUuidGenerator(&settings.Config{UuidServerId: 2})
|
generator, _ := NewInternalUuidGenerator(&settings.Config{UuidServerId: 2})
|
||||||
expectedUnixTime := time.Now().Unix()
|
expectedUnixTime := time.Now().Unix()
|
||||||
|
|
||||||
@@ -79,17 +79,18 @@ func TestGenerateUuid_1000Times(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateUuid_1000000TimesConcurrent(t *testing.T) {
|
func TestGenerateUuid_1000000TimesConcurrent(t *testing.T) {
|
||||||
|
concurrentCount := 50
|
||||||
generator, _ := NewInternalUuidGenerator(&settings.Config{UuidServerId: 3})
|
generator, _ := NewInternalUuidGenerator(&settings.Config{UuidServerId: 3})
|
||||||
var mutex sync.Mutex
|
var mutex sync.Mutex
|
||||||
var generatedIds sync.Map
|
var generatedIds sync.Map
|
||||||
var waitGroup sync.WaitGroup
|
var waitGroup sync.WaitGroup
|
||||||
|
|
||||||
for i := 0; i < 50; i++ {
|
for routineIndex := 0; routineIndex < concurrentCount; routineIndex++ {
|
||||||
go func() {
|
go func() {
|
||||||
waitGroup.Add(1)
|
waitGroup.Add(1)
|
||||||
|
|
||||||
for j := 0; j < 40000; j++ {
|
for cycle := 0; cycle < 40000; cycle++ {
|
||||||
if j%10000 == 0 { // echo server can only generate 500,000 (50 * 10000) uuids in one second
|
if cycle%10000 == 0 { // each server can only generate 500,000 (50 * 10000) uuids in one second
|
||||||
time.Sleep(1000 * time.Millisecond)
|
time.Sleep(1000 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user