MCPcopy
hub / github.com/gogo/protobuf / TestMarshalRace

Function TestMarshalRace

proto/extensions_test.go:656–691  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

654}
655
656func TestMarshalRace(t *testing.T) {
657 ext := &pb.Ext{}
658 m := &pb.MyMessage{Count: proto.Int32(4)}
659 if err := proto.SetExtension(m, pb.E_Ext_More, ext); err != nil {
660 t.Fatalf("proto.SetExtension(m, desc, true): got error %q, want nil", err)
661 }
662
663 b, err := proto.Marshal(m)
664 if err != nil {
665 t.Fatalf("Could not marshal message: %v", err)
666 }
667 if err := proto.Unmarshal(b, m); err != nil {
668 t.Fatalf("Could not unmarshal message: %v", err)
669 }
670 // after Unmarshal, the extension is in undecoded form.
671 // GetExtension will decode it lazily. Make sure this does
672 // not race against Marshal.
673
674 errChan := make(chan error, 6)
675 for n := 3; n > 0; n-- {
676 go func() {
677 _, err := proto.Marshal(m)
678 errChan <- err
679 }()
680 go func() {
681 _, err := proto.GetExtension(m, pb.E_Ext_More)
682 errChan <- err
683 }()
684 }
685 for i := 0; i < 6; i++ {
686 err := <-errChan
687 if err != nil {
688 t.Fatal(err)
689 }
690 }
691}

Callers

nothing calls this directly

Calls 5

Int32Function · 0.92
SetExtensionFunction · 0.92
MarshalFunction · 0.92
UnmarshalFunction · 0.92
GetExtensionFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…