50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package summaryqa
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
type retryPurge struct {
|
|
fixtureRepo
|
|
calls chan int
|
|
count int
|
|
}
|
|
|
|
func (r *retryPurge) PurgeExpiredQASources(context.Context, time.Time) error {
|
|
r.count++
|
|
r.calls <- r.count
|
|
if r.count == 1 {
|
|
return errors.New("PRIVATE_FAILURE")
|
|
}
|
|
return nil
|
|
}
|
|
func TestTicket53PurgeRetriesAndStopsWithApplicationContext(t *testing.T) {
|
|
r := &retryPurge{calls: make(chan int, 4)}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
failures := make(chan struct{}, 4)
|
|
done := make(chan struct{})
|
|
go func() { defer close(done); RunPurger(ctx, r, time.Millisecond, func() { failures <- struct{}{} }) }()
|
|
select {
|
|
case <-failures:
|
|
case <-time.After(time.Second):
|
|
t.Fatal("failed purge not reported")
|
|
}
|
|
for i := 1; i <= 2; i++ {
|
|
select {
|
|
case <-r.calls:
|
|
case <-time.After(time.Second):
|
|
t.Fatal("failed purge not retried")
|
|
}
|
|
}
|
|
cancel()
|
|
select {
|
|
case <-done:
|
|
case <-time.After(time.Second):
|
|
t.Fatal("purger leaked after stop")
|
|
}
|
|
}
|