forked from TrueCloudLab/frostfs-node
[#398] pilorama: Disallow applying same operations
1. In redo() we save the old state. 2. If we do redo() for the same operation twice, the old state will be overritten with the new one. 3. This in turn affects undo() and subsequent isAncestor() check. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
5983617069
commit
f2e5dead7e
3 changed files with 162 additions and 1 deletions
70
pkg/local_object_storage/pilorama/batch_test.go
Normal file
70
pkg/local_object_storage/pilorama/batch_test.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
package pilorama
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_removeDuplicatesInPlace(t *testing.T) {
|
||||
testCases := []struct {
|
||||
before []int
|
||||
after []int
|
||||
}{
|
||||
{
|
||||
before: []int{},
|
||||
after: []int{},
|
||||
},
|
||||
{
|
||||
before: []int{1},
|
||||
after: []int{1},
|
||||
},
|
||||
{
|
||||
before: []int{1, 2},
|
||||
after: []int{1, 2},
|
||||
},
|
||||
{
|
||||
before: []int{1, 2, 3},
|
||||
after: []int{1, 2, 3},
|
||||
},
|
||||
{
|
||||
before: []int{1, 1, 2},
|
||||
after: []int{1, 2},
|
||||
},
|
||||
{
|
||||
before: []int{1, 2, 2},
|
||||
after: []int{1, 2},
|
||||
},
|
||||
{
|
||||
before: []int{1, 2, 2, 3},
|
||||
after: []int{1, 2, 3},
|
||||
},
|
||||
{
|
||||
before: []int{1, 1, 1},
|
||||
after: []int{1},
|
||||
},
|
||||
{
|
||||
before: []int{1, 1, 2, 2},
|
||||
after: []int{1, 2},
|
||||
},
|
||||
{
|
||||
before: []int{1, 1, 1, 2, 3, 3, 3},
|
||||
after: []int{1, 2, 3},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ops := make([]*Move, len(tc.before))
|
||||
for i := range ops {
|
||||
ops[i] = &Move{Meta: Meta{Time: Timestamp(tc.before[i])}}
|
||||
}
|
||||
|
||||
expected := make([]*Move, len(tc.after))
|
||||
for i := range expected {
|
||||
expected[i] = &Move{Meta: Meta{Time: Timestamp(tc.after[i])}}
|
||||
}
|
||||
|
||||
actual := removeDuplicatesInPlace(ops)
|
||||
require.Equal(t, expected, actual, "%d", tc.before)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue