File: concurrency_test.go

package info (click to toggle)
golang-gogoprotobuf 1.0.0%2Bgit20180330.1ef32a8b-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,932 kB
  • sloc: makefile: 462; sh: 23
file content (31 lines) | stat: -rw-r--r-- 529 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package stdtypes

import (
	"io/ioutil"
	"sync"
	"testing"

	"github.com/gogo/protobuf/proto"
)

func TestConcurrentTextMarshal(t *testing.T) {
	// Verify that there are no race conditions when calling
	// TextMarshaler.Marshal on a protobuf message that contains a StdDuration

	std := StdTypes{}
	var wg sync.WaitGroup

	tm := proto.TextMarshaler{}

	for i := 0; i < 2; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			err := tm.Marshal(ioutil.Discard, &std)
			if err != nil {
				t.Fatal(err)
			}
		}()
	}
	wg.Wait()
}