Skip to content

Printing a protobuf message changes its equality #1173

@veqryn

Description

@veqryn

What version of protobuf and what language are you using?
Version: v1.4.2

What did you do?

func TestTimestampWKT(t *testing.T) {
	now := time.Now()

	pbt1, err := ptypes.TimestampProto(now)
	if err != nil {
		panic(err)
	}

	pbt2, err := ptypes.TimestampProto(now)
	if err != nil {
		panic(err)
	}

	if !reflect.DeepEqual(pbt1, pbt2) {
		t.Fatalf("Should be equal: %#v, %#v", pbt1, pbt2)
	}

	fmt.Println(pbt1)

	if !reflect.DeepEqual(pbt1, pbt2) {
		t.Fatalf("Should still be equal: %#v, %#v", pbt1, pbt2)
	}
}

What did you expect to see?
Test should pass

What did you see instead?
Test fails with:

=== RUN   TestTimestampWKT
seconds:1594889122 nanos:308953600
    TestTimestampWKT: endpoint_pixel_counts_test.go:139: Should still be equal: &timestamppb.Timestamp{state:impl.MessageState{NoUnkeyedLiterals:pragma.NoUnkeyedLiterals{}, DoNotCompare:pragma.DoNotCompare{}, DoNotCopy:pragma.DoNotCopy{}, atomicMessageInfo:(*impl.MessageInfo)(0xc0000908c0)}, sizeCache:0, unknownFields:[]uint8(nil), Seconds:1594889122, Nanos:308953600}, &timestamppb.Timestamp{state:impl.MessageState{NoUnkeyedLiterals:pragma.NoUnkeyedLiterals{}, DoNotCompare:pragma.DoNotCompare{}, DoNotCopy:pragma.DoNotCopy{}, atomicMessageInfo:(*impl.MessageInfo)(nil)}, sizeCache:0, unknownFields:[]uint8(nil), Seconds:1594889122, Nanos:308953600}
--- FAIL: TestTimestampWKT (0.00s)
FAIL

Anything else we should know about your project / environment?
This bug came up when I tried upgrading to the newest package version (from v1.3.5).
We have a test that uses gomock, and it takes in a protobuff with WKT timestamps in it.
Previously this test passed, but now it fails because we are printing the protobuf at some point.
This really should still pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions