diff --git a/codec/types/any_test.go b/codec/types/any_test.go index f5ae3a1fd6..cd211c0f00 100644 --- a/codec/types/any_test.go +++ b/codec/types/any_test.go @@ -35,8 +35,10 @@ func TestNewAnyWithCustomTypeURLWithErrorNoAllocation(t *testing.T) { any, err := types.NewAnyWithCustomTypeURL(eom, fauxURL) runtime.ReadMemStats(&ms2) // Ensure that no fresh allocation was made. - if diff := ms2.HeapAlloc - ms1.HeapAlloc; diff > 0 { - t.Errorf("Unexpected allocation of %d bytes", diff) + if ms2.HeapAlloc > ms1.HeapAlloc { + // In some cases, `ms1.HeapAlloc` is larger than `ms2.HeapAlloc`. + // It is probably because the gc worked. + t.Errorf("Unexpected allocation of %d bytes", ms2.HeapAlloc - ms1.HeapAlloc) } if err == nil { t.Fatal("err wasn't returned")