fix racy tests when editing xl.getDisks (#8879)

This commit is contained in:
Harshavardhana 2020-01-23 11:50:09 -08:00 committed by kannappanr
parent b9c48e0ab0
commit 1ffbb5c24c
3 changed files with 12 additions and 0 deletions

View File

@ -1590,12 +1590,14 @@ func TestWebObjectLayerFaultyDisks(t *testing.T) {
z := obj.(*xlZones)
xl := z.zones[0].sets[0]
xlDisks := xl.getDisks()
z.zones[0].xlDisksMu.Lock()
xl.getDisks = func() []StorageAPI {
for i, d := range xlDisks {
xlDisks[i] = newNaughtyDisk(d, nil, errFaultyDisk)
}
return xlDisks
}
z.zones[0].xlDisksMu.Unlock()
// Initialize web rpc endpoint.
apiRouter := initTestWebRPCEndPoint(obj)

View File

@ -270,6 +270,7 @@ func TestHealObjectXL(t *testing.T) {
}
xlDisks := xl.getDisks()
z.zones[0].xlDisksMu.Lock()
xl.getDisks = func() []StorageAPI {
// Nil more than half the disks, to remove write quorum.
for i := 0; i <= len(xlDisks)/2; i++ {
@ -277,6 +278,7 @@ func TestHealObjectXL(t *testing.T) {
}
return xlDisks
}
z.zones[0].xlDisksMu.Unlock()
// Try healing now, expect to receive errDiskNotFound.
_, err = obj.HealObject(context.Background(), bucket, object, false, false, madmin.HealDeepScan)

View File

@ -217,12 +217,14 @@ func TestXLDeleteObjectDiskNotFound(t *testing.T) {
// for a 16 disk setup, quorum is 9. To simulate disks not found yet
// quorum is available, we remove disks leaving quorum disks behind.
xlDisks := xl.getDisks()
z.zones[0].xlDisksMu.Lock()
xl.getDisks = func() []StorageAPI {
for i := range xlDisks[:7] {
xlDisks[i] = newNaughtyDisk(xlDisks[i], nil, errFaultyDisk)
}
return xlDisks
}
z.zones[0].xlDisksMu.Unlock()
err = obj.DeleteObject(context.Background(), bucket, object)
if err != nil {
t.Fatal(err)
@ -236,11 +238,13 @@ func TestXLDeleteObjectDiskNotFound(t *testing.T) {
// Remove one more disk to 'lose' quorum, by setting it to nil.
xlDisks = xl.getDisks()
z.zones[0].xlDisksMu.Lock()
xl.getDisks = func() []StorageAPI {
xlDisks[7] = nil
xlDisks[8] = nil
return xlDisks
}
z.zones[0].xlDisksMu.Unlock()
err = obj.DeleteObject(context.Background(), bucket, object)
// since majority of disks are not available, metaquorum is not achieved and hence errXLReadQuorum error
if err != toObjectErr(errXLReadQuorum, bucket, object) {
@ -293,9 +297,11 @@ func TestGetObjectNoQuorum(t *testing.T) {
xlDisks[i] = newNaughtyDisk(xlDisks[i], diskErrors, errFaultyDisk)
}
}
z.zones[0].xlDisksMu.Lock()
xl.getDisks = func() []StorageAPI {
return xlDisks
}
z.zones[0].xlDisksMu.Unlock()
// Fetch object from store.
err = xl.GetObject(context.Background(), bucket, object, 0, int64(len("abcd")), ioutil.Discard, "", opts)
if err != toObjectErr(errXLReadQuorum, bucket, object) {
@ -350,9 +356,11 @@ func TestPutObjectNoQuorum(t *testing.T) {
xlDisks[i] = newNaughtyDisk(xlDisks[i], diskErrors, errFaultyDisk)
}
}
z.zones[0].xlDisksMu.Lock()
xl.getDisks = func() []StorageAPI {
return xlDisks
}
z.zones[0].xlDisksMu.Unlock()
// Upload new content to same object "object"
_, err = obj.PutObject(context.Background(), bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
if err != toObjectErr(errXLWriteQuorum, bucket, object) {