mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-04 02:38:50 +00:00
7259b46773
This change removes most usages of Syntax() from the repository and uses edition features for instead. The appropriate edition feature defaults are loaded for proto2/proto3 when the initialization of the descriptors start. All of these changes were tested on the Google corpus. Change-Id: Ieca076a2b38ca8e50e084cd32e725b7b3dcb4171 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/572435 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Stapelberg <stapelberg@google.com>
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// Copyright 2024 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package race_test
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
epb "google.golang.org/protobuf/internal/testprotos/race/extender"
|
|
mpb "google.golang.org/protobuf/internal/testprotos/race/message"
|
|
)
|
|
|
|
// There must be no other test in this package as we are testing global
|
|
// initialization which only happens once per binary.
|
|
// It tests that it is safe to initialize the descriptor of a message and
|
|
// the descriptor of an extendee of that message in parallel (i.e. no data race).
|
|
func TestConcurrentInitialization(t *testing.T) {
|
|
var wg sync.WaitGroup
|
|
wg.Add(2)
|
|
go func() {
|
|
defer wg.Done()
|
|
m := &mpb.MyMessage{
|
|
I32: proto.Int32(int32(42)),
|
|
}
|
|
// This initializes the descriptor.
|
|
_, err := proto.Marshal(m)
|
|
if err != nil {
|
|
t.Errorf("proto.Marshal(): %v", err)
|
|
}
|
|
}()
|
|
go func() {
|
|
defer wg.Done()
|
|
m := &epb.OtherMessage{
|
|
I32: proto.Int32(int32(42)),
|
|
}
|
|
// This initializes the descriptor including the extension.
|
|
_, err := proto.Marshal(m)
|
|
if err != nil {
|
|
t.Errorf("proto.Marshal(): %v", err)
|
|
}
|
|
}()
|
|
wg.Wait()
|
|
}
|