...
1
2
3
4
5 package race_test
6
7 import (
8 "sync"
9 "testing"
10
11 "google.golang.org/protobuf/proto"
12
13 epb "google.golang.org/protobuf/internal/testprotos/race/extender"
14 mpb "google.golang.org/protobuf/internal/testprotos/race/message"
15 )
16
17
18
19
20
21 func TestConcurrentInitialization(t *testing.T) {
22 var wg sync.WaitGroup
23 wg.Add(2)
24 go func() {
25 defer wg.Done()
26 m := &mpb.MyMessage{
27 I32: proto.Int32(int32(42)),
28 }
29
30 _, err := proto.Marshal(m)
31 if err != nil {
32 t.Errorf("proto.Marshal(): %v", err)
33 }
34 }()
35 go func() {
36 defer wg.Done()
37 m := &epb.OtherMessage{
38 I32: proto.Int32(int32(42)),
39 }
40
41 _, err := proto.Marshal(m)
42 if err != nil {
43 t.Errorf("proto.Marshal(): %v", err)
44 }
45 }()
46 wg.Wait()
47 }
48
View as plain text