...

Source file src/github.com/gogo/protobuf/test/stdtypes/concurrency_test.go

Documentation: github.com/gogo/protobuf/test/stdtypes

     1  package stdtypes
     2  
     3  import (
     4  	"io/ioutil"
     5  	"sync"
     6  	"testing"
     7  
     8  	"github.com/gogo/protobuf/proto"
     9  )
    10  
    11  func TestConcurrentTextMarshal(t *testing.T) {
    12  	// Verify that there are no race conditions when calling
    13  	// TextMarshaler.Marshal on a protobuf message that contains a StdDuration
    14  
    15  	std := StdTypes{}
    16  	var wg sync.WaitGroup
    17  
    18  	tm := proto.TextMarshaler{}
    19  
    20  	for i := 0; i < 2; i++ {
    21  		wg.Add(1)
    22  		go func() {
    23  			defer wg.Done()
    24  			err := tm.Marshal(ioutil.Discard, &std)
    25  			if err != nil {
    26  				t.Fatal(err)
    27  			}
    28  		}()
    29  	}
    30  	wg.Wait()
    31  }
    32  

View as plain text