(t *testing.T)
| 607 | } |
| 608 | |
| 609 | func TestMarshalRace(t *testing.T) { |
| 610 | ext := &pb2.Ext{} |
| 611 | m := &pb2.MyMessage{Count: proto.Int32(4)} |
| 612 | if err := proto.SetExtension(m, pb2.E_Ext_More, ext); err != nil { |
| 613 | t.Fatalf("proto.SetExtension(m, desc, true): got error %q, want nil", err) |
| 614 | } |
| 615 | |
| 616 | b, err := proto.Marshal(m) |
| 617 | if err != nil { |
| 618 | t.Fatalf("Could not marshal message: %v", err) |
| 619 | } |
| 620 | if err := proto.Unmarshal(b, m); err != nil { |
| 621 | t.Fatalf("Could not unmarshal message: %v", err) |
| 622 | } |
| 623 | // after Unmarshal, the extension is in undecoded form. |
| 624 | // GetExtension will decode it lazily. Make sure this does |
| 625 | // not race against Marshal. |
| 626 | |
| 627 | wg := sync.WaitGroup{} |
| 628 | errs := make(chan error, 3) |
| 629 | for n := 3; n > 0; n-- { |
| 630 | wg.Add(1) |
| 631 | go func() { |
| 632 | defer wg.Done() |
| 633 | _, err := proto.Marshal(m) |
| 634 | errs <- err |
| 635 | }() |
| 636 | } |
| 637 | wg.Wait() |
| 638 | close(errs) |
| 639 | |
| 640 | for err = range errs { |
| 641 | if err != nil { |
| 642 | t.Fatal(err) |
| 643 | } |
| 644 | } |
| 645 | } |
nothing calls this directly
no test coverage detected