Out of memory error on comparing protobuf types
Currently, attempt to compare protobuf-generated types (from *.protoc files) leads to hang or
fatal error: runtime: out of memory
Maybe, it can be solved by respecting pragma.DoNotCompare during executing assert.Equal and similar requests.
It happens at
File: ../../github.com/stretchr/testify/assert/assertions.go
1567: func diff(expected interface{}, actual interface{}) string ..
and then call for spewConfig.Sdump()
Related issue: https://github.com/davecgh/go-spew/issues/66
Also, setting spew.ConfigState.MaxDepth to reasonable value helps prevent hanging.
Related: https://github.com/stretchr/testify/issues/758
"github.com/sanity-io/litter" does not appear to suffer from the same bug as spew: https://play.golang.org/p/_1Q8xVsfLdm
Not sure how much effort, or if it is possible at all, to replace spew with this one.
I think setting spew.ConfigState.MaxDepth to something reasonable is something that should be done ASAP. My tests started grinding to a halt after upgrading to the newest version of the Protobuf stack. Setting the MaxDepth to 10 worked fine for me, would that be a reasonable default? From my understanding, this would only apply to structs that are nested deeper than 10 levels, something I assume is going to be extremely rare.
I don't think this is the same problem as davecgh/go-spew#66.
davecgh/go-spew#66 is a recursion in type definition, and it does not produce output as it never gets the type's name because of the recursion in the type definition.
However, with protobuf generated message, it does generate output if I use Dump directly instead of SDump. I am not able to get a full output, but from the partial output I got, it seems that the hang here is just because the message contains too much information. I don't think there is unhandled recursion inside. Some recursion of data are correctly marked as "already shown"
I waited for a few minutes and got a partial output of more than 6.6 million lines, and found a lot of duplications inside.
If there is no easy way to fix the diff issue, can we have a new option or method, like EqualWithoutDiff, to just check the equity without output the diff?
Deep comparing the two structs are quite fast, but dumping is too slow.
@fefe982 You could perhaps combine https://godoc.org/google.golang.org/protobuf/proto#Equal with assert.True if you don't want to see the diffs.
If you need the diffs, the protocmp package works really well as a workaround:
import (
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/testing/protocmp"
)
// ...
if diff := cmp.Diff(x, y, protocmp.Transform()); diff != "" {
t.Errorf("Unexpected difference:\n%v", diff)
}