mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 02:02:43 +00:00
* add warning for when MAP_POPULATE mmap flag not set * Make mmap flags method handle any flags, where MAP_POPULATE is just one of them * Only have the log print out on restores * Add test, make logic more consistent * Add changelog * Add godoc for test * Make test less dangerous
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
//go:build !386 && !arm
|
|
|
|
package raft
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
func Test_BoltOptions(t *testing.T) {
|
|
t.Parallel()
|
|
key := "VAULT_RAFT_INITIAL_MMAP_SIZE"
|
|
|
|
testCases := []struct {
|
|
name string
|
|
env string
|
|
expectedSize int
|
|
}{
|
|
{"none", "", 100 * 1024 * 1024 * 1024},
|
|
{"5MB", strconv.Itoa(5 * 1024 * 1024), 5 * 1024 * 1024},
|
|
{"negative", "-1", 0},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if tc.env != "" {
|
|
current := os.Getenv(key)
|
|
defer os.Setenv(key, current)
|
|
os.Setenv(key, tc.env)
|
|
}
|
|
|
|
o := boltOptions("")
|
|
|
|
if o.InitialMmapSize != tc.expectedSize {
|
|
t.Errorf("expected InitialMmapSize to be %d but it was %d", tc.expectedSize, o.InitialMmapSize)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestMmapFlags tests the getMmapFlags function, ensuring it returns the appropriate integer representing the desired mmap flag.
|
|
func TestMmapFlags(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
disableMapPopulate bool
|
|
}{
|
|
{"MAP_POPULATE is enabled", false},
|
|
{"MAP_POPULATE disabled by env var", true},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if tc.disableMapPopulate {
|
|
t.Setenv("VAULT_RAFT_DISABLE_MAP_POPULATE", "true")
|
|
}
|
|
|
|
isEnabled := usingMapPopulate(getMmapFlags(""))
|
|
if tc.disableMapPopulate && isEnabled {
|
|
t.Error("expected MAP_POPULATE to be disabled but it was enabled")
|
|
}
|
|
})
|
|
}
|
|
}
|