This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from puppetlabs/features/add-backoff-to-recove…
…ry-descriptor Features/add backoff to recovery descriptor
- Loading branch information
Showing
19 changed files
with
1,603 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
/node_modules/ | ||
|
||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package scheduler | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type mockErrorDescriptor struct { | ||
errCount int | ||
successAfterCount int | ||
} | ||
|
||
func (d *mockErrorDescriptor) Run(ctx context.Context, pc chan<- Process) error { | ||
if d.errCount >= 0 && d.successAfterCount != 0 { | ||
err := fmt.Errorf("err count %d", d.errCount) | ||
d.errCount-- | ||
d.successAfterCount-- | ||
|
||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func TestRecoverySchedulerStops(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) | ||
|
||
mock := &mockErrorDescriptor{ | ||
errCount: 10, | ||
// make sure we never succeed | ||
successAfterCount: 15, | ||
} | ||
|
||
opts := RecoveryDescriptorOptions{ | ||
MaxRetries: 10, | ||
} | ||
descriptor := NewRecoveryDescriptorWithOptions(mock, opts) | ||
|
||
pc := make(chan Process) | ||
|
||
defer cancel() | ||
|
||
require.Error(t, descriptor.Run(ctx, pc)) | ||
} | ||
|
||
type mockRetryResetDescriptor struct { | ||
count int | ||
successDuration time.Duration | ||
cancel context.CancelFunc | ||
} | ||
|
||
func (d *mockRetryResetDescriptor) Run(ctx context.Context, pc chan<- Process) error { | ||
if d.count == 0 { | ||
<-time.After(d.successDuration) | ||
d.cancel() | ||
return nil | ||
} | ||
|
||
err := fmt.Errorf("err count %d", d.count) | ||
d.count-- | ||
|
||
return err | ||
} | ||
|
||
func TestRecoverySchedulerRetryCountReset(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) | ||
|
||
successDuration := time.Second * 1 | ||
|
||
mock := &mockRetryResetDescriptor{ | ||
count: 5, | ||
cancel: cancel, | ||
successDuration: successDuration, | ||
} | ||
|
||
opts := RecoveryDescriptorOptions{ | ||
MaxRetries: 10, | ||
ResetRetriesAfter: successDuration - (time.Millisecond * 500), | ||
} | ||
descriptor := NewRecoveryDescriptorWithOptions(mock, opts) | ||
|
||
pc := make(chan Process) | ||
|
||
defer cancel() | ||
|
||
require.NoError(t, descriptor.Run(ctx, pc)) | ||
require.Equal(t, 0, mock.count) | ||
} |
Oops, something went wrong.