Skip to content

Commit

Permalink
Merge pull request #47 from ccpwcn/dev
Browse files Browse the repository at this point in the history
fix: 修复雪花算法测试用例中的map并发写问题
  • Loading branch information
ccpwcn authored Jun 17, 2024
2 parents d43a084 + 9ff5f6b commit 0be075c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions snowflake_generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ func Test_GenericSnowflake_Concurrent_Id(t *testing.T) {
} else {
const count = 5
const machine = 3
var buffer = make(map[int64]int8, count*3)
var buffer sync.Map
var wg sync.WaitGroup
for i := 1; i <= machine; i++ {
wg.Add(1)
go func(i int64) {
for j := 0; j < count; j++ {
id := GetSnowflakeId[int64]()
if _, ok := buffer[id]; ok {
if _, ok := buffer.Load(id); ok {
t.Errorf("ID %+v 重复了", id)
} else {
buffer[id] = 1
buffer.Store(id, 1)
t.Logf("ID %+v\n", id)
}
}
Expand All @@ -74,17 +74,17 @@ func Test_GenericSnowflake_Concurrent_Id_String(t *testing.T) {
} else {
const count = 5
const machine = 3
var buffer = make(map[string]int8, count*3)
var buffer sync.Map
var wg sync.WaitGroup
for i := 1; i <= machine; i++ {
wg.Add(1)
go func(i string) {
for j := 0; j < count; j++ {
id := GetSnowflakeId[string]()
if _, ok := buffer[id]; ok {
if _, ok := buffer.Load(id); ok {
t.Errorf("ID %+v 重复了", id)
} else {
buffer[id] = 1
buffer.Store(id, 1)
t.Logf("ID %+v\n", id)
}
}
Expand Down
6 changes: 3 additions & 3 deletions snowflake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ func TestSnowflake_Concurrent_Id(t *testing.T) {
} else {
const count = 5
const machine = 3
var buffer = make(map[int64]int8, count*3)
var buffer sync.Map
var wg sync.WaitGroup
for i := 1; i <= machine; i++ {
wg.Add(1)
go func(i int64) {
for j := 0; j < count; j++ {
id := SnowflakeId()
if _, ok := buffer[id]; ok {
if _, ok := buffer.Load(id); ok {
t.Errorf("ID %+v 重复了", id)
} else {
buffer[id] = 1
buffer.Store(id, 1)
t.Logf("ID %+v\n", id)
}
}
Expand Down

0 comments on commit 0be075c

Please sign in to comment.