Use extensions to cause partial backup failures
This commit is contained in:
parent
5ac0c135bd
commit
735ea9fa09
@ -411,6 +411,9 @@ type driveStats struct {
|
|||||||
itemsFound int64
|
itemsFound int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// global counter
|
||||||
|
var ctr int32
|
||||||
|
|
||||||
// populateItems iterates through items added to the collection
|
// populateItems iterates through items added to the collection
|
||||||
// and uses the collection `itemReader` to read the item
|
// and uses the collection `itemReader` to read the item
|
||||||
func (oc *Collection) populateItems(ctx context.Context, errs *fault.Bus) {
|
func (oc *Collection) populateItems(ctx context.Context, errs *fault.Bus) {
|
||||||
@ -452,17 +455,26 @@ func (oc *Collection) populateItems(ctx context.Context, errs *fault.Bus) {
|
|||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
defer func() { <-semaphoreCh }()
|
defer func() { <-semaphoreCh }()
|
||||||
|
|
||||||
|
itf := []extensions.CreateItemExtensioner{
|
||||||
|
&extensions.MockItemExtensionFactory{
|
||||||
|
ItemNumber: ctr,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
atomic.AddInt32(&ctr, 1)
|
||||||
|
|
||||||
// Read the item
|
// Read the item
|
||||||
oc.populateDriveItem(
|
oc.populateDriveItem(
|
||||||
ctx,
|
ctx,
|
||||||
parentPath,
|
parentPath,
|
||||||
item,
|
item,
|
||||||
&stats,
|
&stats,
|
||||||
oc.ctrl.ItemExtensionFactory,
|
itf,
|
||||||
errs)
|
errs)
|
||||||
|
|
||||||
folderProgress <- struct{}{}
|
folderProgress <- struct{}{}
|
||||||
}(item)
|
}(item)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|||||||
@ -29,9 +29,15 @@ type MockExtension struct {
|
|||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
FailOnRead bool
|
FailOnRead bool
|
||||||
FailOnClose bool
|
FailOnClose bool
|
||||||
|
ItemNumber int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me *MockExtension) Read(p []byte) (int, error) {
|
func (me *MockExtension) Read(p []byte) (int, error) {
|
||||||
|
// randomly fail with 50% prob
|
||||||
|
if me.ItemNumber > 3 {
|
||||||
|
return 0, clues.New("mock read error")
|
||||||
|
}
|
||||||
|
|
||||||
if me.FailOnRead {
|
if me.FailOnRead {
|
||||||
return 0, clues.New("mock read error")
|
return 0, clues.New("mock read error")
|
||||||
}
|
}
|
||||||
@ -55,6 +61,11 @@ func (me *MockExtension) Read(p []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (me *MockExtension) Close() error {
|
func (me *MockExtension) Close() error {
|
||||||
|
// if me.itemCount > 3 {
|
||||||
|
// return clues.New("mock close error")
|
||||||
|
// }
|
||||||
|
|
||||||
|
// atomic.AddInt32(&me.itemCount, 1)
|
||||||
if me.FailOnClose {
|
if me.FailOnClose {
|
||||||
return clues.New("mock close error")
|
return clues.New("mock close error")
|
||||||
}
|
}
|
||||||
@ -66,6 +77,8 @@ func (me *MockExtension) Close() error {
|
|||||||
|
|
||||||
me.ExtData.Data[KNumBytes] = me.NumBytes
|
me.ExtData.Data[KNumBytes] = me.NumBytes
|
||||||
me.ExtData.Data[KCrc32] = me.Crc32
|
me.ExtData.Data[KCrc32] = me.Crc32
|
||||||
|
me.ExtData.Data["ItemNumber"] = me.ItemNumber
|
||||||
|
|
||||||
logger.Ctx(me.Ctx).Infow(
|
logger.Ctx(me.Ctx).Infow(
|
||||||
"mock extension closed",
|
"mock extension closed",
|
||||||
KNumBytes, me.NumBytes, KCrc32, me.Crc32)
|
KNumBytes, me.NumBytes, KCrc32, me.Crc32)
|
||||||
@ -77,6 +90,7 @@ type MockItemExtensionFactory struct {
|
|||||||
FailOnFactoryCreation bool
|
FailOnFactoryCreation bool
|
||||||
FailOnRead bool
|
FailOnRead bool
|
||||||
FailOnClose bool
|
FailOnClose bool
|
||||||
|
ItemNumber int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockItemExtensionFactory) CreateItemExtension(
|
func (m *MockItemExtensionFactory) CreateItemExtension(
|
||||||
@ -96,5 +110,6 @@ func (m *MockItemExtensionFactory) CreateItemExtension(
|
|||||||
ExtData: extData,
|
ExtData: extData,
|
||||||
FailOnRead: m.FailOnRead,
|
FailOnRead: m.FailOnRead,
|
||||||
FailOnClose: m.FailOnClose,
|
FailOnClose: m.FailOnClose,
|
||||||
|
ItemNumber: m.ItemNumber,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user