ROOTPLOIT
Server: LiteSpeed
System: Linux in-mum-web1878.main-hosting.eu 5.14.0-570.21.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 11 07:22:35 EDT 2025 x86_64
User: u435929562 (435929562)
PHP: 7.4.33
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/go/pkg/mod/google.golang.org/[email protected]/internal/race_test/file_desc_init/race_test.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()
}