[#49] message/test: Add test for zero-alloc StableSize()
All checks were successful
Tests and linters / Tests (1.19) (pull_request) Successful in 54s
Tests and linters / Lint (pull_request) Successful in 1m44s
Tests and linters / Tests (1.20) (pull_request) Successful in 2m28s
Tests and linters / Tests with -race (pull_request) Successful in 4m46s

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)