"refactor(common): 重构序列化工具包,将serialize重命名为utils并添加bitset组件"
This commit is contained in:
4
common/utils/sturc/test_pack_init/doc.go
Normal file
4
common/utils/sturc/test_pack_init/doc.go
Normal file
@@ -0,0 +1,4 @@
|
||||
package test_pack_init
|
||||
|
||||
// This is a placeholder package for a test on specific race detector report on
|
||||
// default Options initialization.
|
||||
29
common/utils/sturc/test_pack_init/pack_init_test.go
Normal file
29
common/utils/sturc/test_pack_init/pack_init_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package test_pack_init
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/lunixbochs/struc"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type Example struct {
|
||||
I int `struc:int`
|
||||
}
|
||||
|
||||
// TestParallelPack checks whether Pack is goroutine-safe. Run it with -race flag.
|
||||
// Keep it as a single test in package since it is likely to be triggered on initialization
|
||||
// of global objects reported as a data race by race detector.
|
||||
func TestParallelPack(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
val := Example{}
|
||||
for i := 0; i < 2; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
var buf bytes.Buffer
|
||||
_ = struc.Pack(&buf, &val)
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
Reference in New Issue
Block a user