Skip to content

Commit

Permalink
Merge 1a15c4b into backport/violethynes/fix-mount-test-locking/carefu…
Browse files Browse the repository at this point in the history
…lly-immortal-bluebird
  • Loading branch information
hc-github-team-secure-vault-core authored Nov 20, 2024
2 parents 0f8ddcc + 1a15c4b commit 862e178
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions vault/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/armon/go-metrics"
"github.com/go-test/deep"
"github.com/hashicorp/vault/audit"
"github.com/hashicorp/vault/helper/locking"
"github.com/hashicorp/vault/helper/metricsutil"
"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/helper/testhelpers/corehelpers"
Expand Down Expand Up @@ -115,7 +116,7 @@ func TestLogicalMountMetrics(t *testing.T) {

func TestCore_DefaultMountTable(t *testing.T) {
c, keys, _ := TestCoreUnsealed(t)
verifyDefaultTable(t, c.mounts, 4)
verifyDefaultTable(t, c.mounts, 4, c.mountsLock)

// Start a second core with same physical
inmemSink := metrics.NewInmemSink(1000000*time.Hour, 2000000*time.Hour)
Expand All @@ -141,6 +142,8 @@ func TestCore_DefaultMountTable(t *testing.T) {
}
}

c.mountsLock.Lock()
defer c.mountsLock.Unlock()
if diff := deep.Equal(c.mounts.sortEntriesByPath(), c2.mounts.sortEntriesByPath()); len(diff) > 0 {
t.Fatalf("mismatch: %v", diff)
}
Expand Down Expand Up @@ -187,6 +190,8 @@ func TestCore_Mount(t *testing.T) {
}

// Verify matching mount tables
c.mountsLock.Lock()
defer c.mountsLock.Unlock()
if diff := deep.Equal(c.mounts.sortEntriesByPath(), c2.mounts.sortEntriesByPath()); len(diff) > 0 {
t.Fatalf("mismatch: %v", diff)
}
Expand Down Expand Up @@ -259,6 +264,8 @@ func TestCore_Mount_kv_generic(t *testing.T) {
}

// Verify matching mount tables
c.mountsLock.Lock()
defer c.mountsLock.Unlock()
if diff := deep.Equal(c.mounts.sortEntriesByPath(), c2.mounts.sortEntriesByPath()); len(diff) > 0 {
t.Fatalf("mismatch: %v", diff)
}
Expand Down Expand Up @@ -717,7 +724,7 @@ func TestCore_Remount_Protected(t *testing.T) {
func TestDefaultMountTable(t *testing.T) {
c, _, _ := TestCoreUnsealed(t)
table := c.defaultMountTable()
verifyDefaultTable(t, table, 3)
verifyDefaultTable(t, table, 3, c.mountsLock)
}

func TestCore_MountTable_UpgradeToTyped(t *testing.T) {
Expand Down Expand Up @@ -886,7 +893,9 @@ func testCore_MountTable_UpgradeToTyped_Common(
}
}

func verifyDefaultTable(t *testing.T, table *MountTable, expected int) {
func verifyDefaultTable(t *testing.T, table *MountTable, expected int, mountsLock locking.RWMutex) {
mountsLock.Lock()
defer mountsLock.Unlock()
if len(table.Entries) != expected {
t.Fatalf("bad: %v", table.Entries)
}
Expand Down

0 comments on commit 862e178

Please sign in to comment.