Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vtorc: fetch shard names only every --topo-information-refresh-duration #17319

Prev Previous commit
Next Next commit
fix test
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Dec 17, 2024
commit 54433aad5a3c7c0fbd46e7a6c8ef2b8d3da9e6a0
35 changes: 35 additions & 0 deletions go/vt/vtorc/inst/keyspace_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package inst

import (
"testing"
"time"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -124,3 +125,37 @@ func TestSaveAndReadKeyspace(t *testing.T) {
})
}
}

func TestDeleteStaleKeyspaces(t *testing.T) {
// Clear the database after the test. The easiest way to do that is to run all the initialization commands again.
defer func() {
db.ClearVTOrcDatabase()
}()

keyspaceInfo := &topo.KeyspaceInfo{
Keyspace: &topodatapb.Keyspace{
KeyspaceType: topodatapb.KeyspaceType_NORMAL,
DurabilityPolicy: "none",
BaseKeyspace: "baseKeyspace",
},
}
keyspaceInfo.SetKeyspaceName("ks1")
err := SaveKeyspace(keyspaceInfo)
require.NoError(t, err)

readKeyspaceInfo, err := ReadKeyspace("ks1")
require.NoError(t, err)
require.NotNil(t, readKeyspaceInfo)

// test a staletime before save causes no delete
require.NoError(t, DeleteStaleKeyspaces(time.Now().Add(-time.Hour)))
readKeyspaceInfo, err = ReadKeyspace("ks1")
require.NoError(t, err)
require.NotNil(t, readKeyspaceInfo)

// test statetime of now deletes everything
require.NoError(t, DeleteStaleKeyspaces(time.Now()))
readKeyspaceInfo, err = ReadKeyspace("ks1")
require.Error(t, err)
require.Nil(t, readKeyspaceInfo)
}
Loading