Jelajahi Sumber

all: update to latest in golang/protobuf@b5d812f8

This merges in the following upstream PRs:
* #797: ptypes: More cleanly construct a Timestamp
* #796: ptypes: Avoid assuming time.Duration is nanoseconds
* #805: proto: remove test dependency on experimental packages
* #808: Delete the conformance test

Change-Id: I104189682bbc0a18e3d8460e57f9fcb45f1f4a46
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/166521
Reviewed-by: Herbie Ong <herbie@google.com>
Joe Tsai 6 tahun lalu
induk
melakukan
6ce2da42b4
7 mengubah file dengan 21 tambahan dan 31 penghapusan
  1. 0 1
      Makefile
  2. 1 6
      go.mod
  3. 1 6
      go.sum
  4. 16 12
      proto/extensions_test.go
  5. 1 1
      ptypes/duration.go
  6. 2 4
      ptypes/timestamp.go
  7. 0 1
      regenerate.sh

+ 0 - 1
Makefile

@@ -11,7 +11,6 @@ test:
 	go test ./... ./protoc-gen-go/testdata
 	go test -tags purego ./... ./protoc-gen-go/testdata
 	go build ./protoc-gen-go/testdata/grpc/grpc.pb.go
-	make -C conformance test
 
 clean:
 	go clean ./...

+ 1 - 6
go.mod

@@ -1,8 +1,3 @@
 module github.com/golang/protobuf
 
-require (
-	github.com/golang/protobuf/v2 v2.0.0-20181127193627-d7e97bc71bcb
-	golang.org/x/net v0.0.0-20180926154720-4dfa2610cdf3 // indirect
-	golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
-	golang.org/x/tools v0.0.0-20180928181343-b3c0be4c978b // indirect
-)
+require github.com/golang/protobuf/v2 v2.0.0-20181127193627-d7e97bc71bcb

+ 1 - 6
go.sum

@@ -4,12 +4,7 @@ github.com/golang/protobuf/v2 v2.0.0-20181127193627-d7e97bc71bcb/go.mod h1:MgUD+
 github.com/google/go-cmp v0.2.1-0.20181101181452-745b8ec83783 h1:wVZ6laEGf86tNDTpR5mxFyFIclJJiXCxuJhcQKnsOHk=
 github.com/google/go-cmp v0.2.1-0.20181101181452-745b8ec83783/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
 golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/net v0.0.0-20180926154720-4dfa2610cdf3 h1:dgd4x4kJt7G4k4m93AYLzM8Ni6h2qLTfh9n9vXJT3/0=
-golang.org/x/net v0.0.0-20180926154720-4dfa2610cdf3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/tools v0.0.0-20180904205237-0aa4b8830f48 h1:PIz+xUHW4G/jqfFWeKhQ96ZV/t2HDsXfWj923rV0bZY=
 golang.org/x/tools v0.0.0-20180904205237-0aa4b8830f48/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-golang.org/x/tools v0.0.0-20180928181343-b3c0be4c978b h1:hjfKpJoTfQ2QXKPX9eCDFBZ0t9sDrZL/viAgrN962TQ=
-golang.org/x/tools v0.0.0-20180928181343-b3c0be4c978b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-google.golang.org/genproto v0.0.0-20180831171423-11092d34479b h1:lohp5blsw53GBXtLyLNaTXPXS9pJ1tiTw61ZHUoE9Qw=
 google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=

+ 16 - 12
proto/extensions_test.go

@@ -11,11 +11,11 @@ import (
 	"reflect"
 	"sort"
 	"strings"
+	"sync"
 	"testing"
 
 	"github.com/golang/protobuf/proto"
 	pb "github.com/golang/protobuf/proto/test_proto"
-	"golang.org/x/sync/errgroup"
 )
 
 func TestGetExtensionsWithMissingExtensions(t *testing.T) {
@@ -644,18 +644,22 @@ func TestMarshalRace(t *testing.T) {
 	// GetExtension will decode it lazily. Make sure this does
 	// not race against Marshal.
 
-	var g errgroup.Group
+	wg := sync.WaitGroup{}
+	errs := make(chan error, 3)
 	for n := 3; n > 0; n-- {
-		g.Go(func() error {
+		wg.Add(1)
+		go func() {
+			defer wg.Done()
 			_, err := proto.Marshal(m)
-			return err
-		})
-		g.Go(func() error {
-			_, err := proto.GetExtension(m, pb.E_Ext_More)
-			return err
-		})
-	}
-	if err := g.Wait(); err != nil {
-		t.Fatal(err)
+			errs <- err
+		}()
+	}
+	wg.Wait()
+	close(errs)
+
+	for err = range errs {
+		if err != nil {
+			t.Fatal(err)
+		}
 	}
 }

+ 1 - 1
ptypes/duration.go

@@ -55,7 +55,7 @@ func Duration(p *durpb.Duration) (time.Duration, error) {
 		return 0, fmt.Errorf("duration: %v is out of range for time.Duration", p)
 	}
 	if p.Nanos != 0 {
-		d += time.Duration(p.Nanos)
+		d += time.Duration(p.Nanos) * time.Nanosecond
 		if (d < 0) != (p.Nanos < 0) {
 			return 0, fmt.Errorf("duration: %v is out of range for time.Duration", p)
 		}

+ 2 - 4
ptypes/timestamp.go

@@ -84,11 +84,9 @@ func TimestampNow() *tspb.Timestamp {
 // TimestampProto converts the time.Time to a google.protobuf.Timestamp proto.
 // It returns an error if the resulting Timestamp is invalid.
 func TimestampProto(t time.Time) (*tspb.Timestamp, error) {
-	seconds := t.Unix()
-	nanos := int32(t.Sub(time.Unix(seconds, 0)))
 	ts := &tspb.Timestamp{
-		Seconds: seconds,
-		Nanos:   nanos,
+		Seconds: t.Unix(),
+		Nanos:   int32(t.Nanosecond()),
 	}
 	if err := validateTimestamp(ts); err != nil {
 		return nil, err

+ 0 - 1
regenerate.sh

@@ -17,7 +17,6 @@ fi
 
 # Generate various test protos.
 PROTO_DIRS=(
-  conformance/internal/conformance_proto
   jsonpb/jsonpb_test_proto
   proto
   protoc-gen-go/testdata