[#49] message/test: Add test for zero-alloc StableSize()

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-07-26 18:13:05 +03:00
parent 43ad0f114c
commit 7133a01ccf

View file

@ -17,6 +17,7 @@ type jsonMessage interface {
type binaryMessage interface { type binaryMessage interface {
StableMarshal([]byte) []byte StableMarshal([]byte) []byte
StableSize() int
Unmarshal([]byte) error Unmarshal([]byte) error
} }
@ -53,6 +54,11 @@ func TestRPCMessage(t *testing.T, msgGens ...func(empty bool) message.Message) {
} }
if bm, ok := msg.(binaryMessage); ok { if bm, ok := msg.(binaryMessage); ok {
t.Run(fmt.Sprintf("%T.StableSize() does no allocations", bm), func(t *testing.T) {
require.Zero(t, testing.AllocsPerRun(1000, func() {
_ = bm.StableSize()
}))
})
t.Run(fmt.Sprintf("Binary_%T", msg), func(t *testing.T) { t.Run(fmt.Sprintf("Binary_%T", msg), func(t *testing.T) {
data := bm.StableMarshal(nil) data := bm.StableMarshal(nil)