XL: Refactor usage of reduceErrs and consistent behavior. (#2240)

This refactor is also needed in lieu of our quorum
requirement change for the newly understood logic behind
klauspost/reedsolom implementation.
This commit is contained in:
Harshavardhana
2016-07-19 19:24:32 -07:00
committed by Anand Babu (AB) Periasamy
parent f67c930731
commit cef26fd6ea
10 changed files with 95 additions and 164 deletions
+27 -10
View File
@@ -20,23 +20,40 @@ import "testing"
// Test for reduceErrs.
func TestReduceErrs(t *testing.T) {
// List all of all test cases to validate various cases of reduce errors.
testCases := []struct {
errs []error
err error
count int
errs []error
ignoredErrs []error
err error
}{
{[]error{errDiskNotFound, errDiskNotFound, errDiskFull}, errDiskNotFound, 2},
{[]error{errDiskFull, errDiskNotFound, nil, nil}, nil, 2},
{[]error{}, nil, 0},
// Validate if have reduced properly.
{[]error{
errDiskNotFound,
errDiskNotFound,
errDiskFull,
}, []error{}, errDiskNotFound},
// Validate if have no consensus.
{[]error{
errDiskFull,
errDiskNotFound,
nil, nil,
}, []error{}, nil},
// Validate if have consensus and errors ignored.
{[]error{
errVolumeNotFound,
errVolumeNotFound,
errVolumeNotFound,
errDiskNotFound,
errDiskNotFound,
}, []error{errDiskNotFound}, errVolumeNotFound},
{[]error{}, []error{}, nil},
}
// Validates list of all the testcases for returning valid errors.
for i, testCase := range testCases {
gotMax, gotErr := reduceErrs(testCase.errs)
gotErr := reduceErrs(testCase.errs, testCase.ignoredErrs)
if testCase.err != gotErr {
t.Errorf("Test %d : expected %s, got %s", i+1, testCase.err, gotErr)
}
if testCase.count != gotMax {
t.Errorf("Test %d : expected %d, got %d", i+1, testCase.count, gotMax)
}
}
}