forked from TrueCloudLab/frostfs-contract
netmap/tests: move snapshot checking to a separate function
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
cac85313ce
commit
d4c8f2f188
1 changed files with 17 additions and 25 deletions
|
@ -148,17 +148,14 @@ func TestNewEpoch(t *testing.T) {
|
|||
cNm.Invoke(t, stackitem.Null{}, "newEpoch", i+1)
|
||||
|
||||
t.Logf("Epoch: %d, Netmap()", i)
|
||||
s, err := cNm.TestInvoke(t, "netmap")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, s.Len())
|
||||
checkSnapshot(t, s, nodes[i])
|
||||
checkSnapshotCurrent(t, cNm, nodes[i])
|
||||
|
||||
for j := 0; j <= i && j < netmap.DefaultSnapshotCount; j++ {
|
||||
t.Logf("Epoch: %d, diff: %d", i, j)
|
||||
checkSnapshotAt(t, j, cNm, nodes[i-j])
|
||||
}
|
||||
|
||||
_, err = cNm.TestInvoke(t, "snapshot", netmap.DefaultSnapshotCount)
|
||||
_, err := cNm.TestInvoke(t, "snapshot", netmap.DefaultSnapshotCount)
|
||||
require.Error(t, err)
|
||||
require.True(t, strings.Contains(err.Error(), "incorrect diff"))
|
||||
|
||||
|
@ -198,17 +195,14 @@ func TestUpdateSnapshotCount(t *testing.T) {
|
|||
const newCount = netmap.DefaultSnapshotCount + 3
|
||||
cNm.Invoke(t, stackitem.Null{}, "updateSnapshotCount", newCount)
|
||||
|
||||
s, err := cNm.TestInvoke(t, "netmap")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, s.Len())
|
||||
checkSnapshot(t, s, nodes[epochCount-1])
|
||||
checkSnapshotCurrent(t, cNm, nodes[epochCount-1])
|
||||
for i := 0; i < epochCount; i++ {
|
||||
checkSnapshotAt(t, i, cNm, nodes[epochCount-i-1])
|
||||
}
|
||||
for i := epochCount; i < newCount; i++ {
|
||||
checkSnapshotAt(t, i, cNm, nil)
|
||||
}
|
||||
_, err = cNm.TestInvoke(t, "snapshot", int64(newCount))
|
||||
_, err := cNm.TestInvoke(t, "snapshot", int64(newCount))
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("increase size, copy old snapshots", func(t *testing.T) {
|
||||
|
@ -222,17 +216,14 @@ func TestUpdateSnapshotCount(t *testing.T) {
|
|||
const newCount = netmap.DefaultSnapshotCount + 3
|
||||
cNm.Invoke(t, stackitem.Null{}, "updateSnapshotCount", newCount)
|
||||
|
||||
s, err := cNm.TestInvoke(t, "netmap")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, s.Len())
|
||||
checkSnapshot(t, s, nodes[epochCount-1])
|
||||
checkSnapshotCurrent(t, cNm, nodes[epochCount-1])
|
||||
for i := 0; i < newCount-3; i++ {
|
||||
checkSnapshotAt(t, i, cNm, nodes[epochCount-i-1])
|
||||
}
|
||||
for i := newCount - 3; i < newCount; i++ {
|
||||
checkSnapshotAt(t, i, cNm, nil)
|
||||
}
|
||||
_, err = cNm.TestInvoke(t, "snapshot", int64(newCount))
|
||||
_, err := cNm.TestInvoke(t, "snapshot", int64(newCount))
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("decrease size, small decrease", func(t *testing.T) {
|
||||
|
@ -246,14 +237,11 @@ func TestUpdateSnapshotCount(t *testing.T) {
|
|||
const newCount = netmap.DefaultSnapshotCount/2 + 2
|
||||
cNm.Invoke(t, stackitem.Null{}, "updateSnapshotCount", newCount)
|
||||
|
||||
s, err := cNm.TestInvoke(t, "netmap")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, s.Len())
|
||||
checkSnapshot(t, s, nodes[epochCount-1])
|
||||
checkSnapshotCurrent(t, cNm, nodes[epochCount-1])
|
||||
for i := 0; i < newCount; i++ {
|
||||
checkSnapshotAt(t, i, cNm, nodes[epochCount-i-1])
|
||||
}
|
||||
_, err = cNm.TestInvoke(t, "snapshot", int64(newCount))
|
||||
_, err := cNm.TestInvoke(t, "snapshot", int64(newCount))
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("decrease size, big decrease", func(t *testing.T) {
|
||||
|
@ -267,18 +255,22 @@ func TestUpdateSnapshotCount(t *testing.T) {
|
|||
const newCount = netmap.DefaultSnapshotCount/2 - 2
|
||||
cNm.Invoke(t, stackitem.Null{}, "updateSnapshotCount", newCount)
|
||||
|
||||
s, err := cNm.TestInvoke(t, "netmap")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, s.Len())
|
||||
checkSnapshot(t, s, nodes[epochCount-1])
|
||||
checkSnapshotCurrent(t, cNm, nodes[epochCount-1])
|
||||
for i := 0; i < newCount; i++ {
|
||||
checkSnapshotAt(t, i, cNm, nodes[epochCount-i-1])
|
||||
}
|
||||
_, err = cNm.TestInvoke(t, "snapshot", int64(newCount))
|
||||
_, err := cNm.TestInvoke(t, "snapshot", int64(newCount))
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func checkSnapshotCurrent(t *testing.T, cNm *neotest.ContractInvoker, nodes []testNodeInfo) {
|
||||
s, err := cNm.TestInvoke(t, "netmap")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, s.Len())
|
||||
checkSnapshot(t, s, nodes)
|
||||
}
|
||||
|
||||
func checkSnapshotAt(t *testing.T, epoch int, cNm *neotest.ContractInvoker, nodes []testNodeInfo) {
|
||||
s, err := cNm.TestInvoke(t, "snapshot", int64(epoch))
|
||||
require.NoError(t, err)
|
||||
|
|
Loading…
Reference in a new issue