diff --git a/raft/raftpb/raft_test.go b/raft/raftpb/raft_test.go new file mode 100644 index 000000000000..46ec5af86e3e --- /dev/null +++ b/raft/raftpb/raft_test.go @@ -0,0 +1,56 @@ +// Copyright 2021 The etcd Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package raftpb + +import ( + "testing" + "unsafe" +) + +func TestProtoMemorySizes(t *testing.T) { + assert := func(size, exp uintptr, name string) { + t.Helper() + if size != exp { + t.Errorf("expected size of %s proto to be %d bytes, found %d bytes", name, exp, size) + } + } + + var e Entry + assert(unsafe.Sizeof(e), 80, "Entry") + + var sm SnapshotMetadata + assert(unsafe.Sizeof(sm), 184, "SnapshotMetadata") + + var s Snapshot + assert(unsafe.Sizeof(s), 240, "Snapshot") + + var m Message + assert(unsafe.Sizeof(m), 392, "Message") + + var hs HardState + assert(unsafe.Sizeof(hs), 56, "HardState") + + var cs ConfState + assert(unsafe.Sizeof(cs), 136, "ConfState") + + var cc ConfChange + assert(unsafe.Sizeof(cc), 80, "ConfChange") + + var ccs ConfChangeSingle + assert(unsafe.Sizeof(ccs), 48, "ConfChangeSingle") + + var ccv2 ConfChangeV2 + assert(unsafe.Sizeof(ccv2), 88, "ConfChangeV2") +}