forked from rosa/hakurei
internal/pkg: abort all pending cures
This cancels all current pending cures without closing the cache. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
"unique"
|
||||
@@ -903,26 +904,46 @@ func TestCache(t *testing.T) {
|
||||
<-wCureDone
|
||||
}, pkg.MustDecode("E4vEZKhCcL2gPZ2Tt59FS3lDng-d_2SKa2i5G_RbDfwGn6EemptFaGLPUDiOa94C")},
|
||||
|
||||
{"cancel hanging", pkg.CValidateKnown, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
|
||||
started := make(chan struct{})
|
||||
go func() {
|
||||
<-started
|
||||
if !c.Cancel(unique.Make(pkg.ID{0xff})) {
|
||||
panic("missed cancellation")
|
||||
{"cancel abort block", pkg.CValidateKnown, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
|
||||
var wg sync.WaitGroup
|
||||
defer wg.Wait()
|
||||
|
||||
var started sync.WaitGroup
|
||||
defer started.Wait()
|
||||
|
||||
blockCures := func(d byte, n int) {
|
||||
started.Add(n)
|
||||
for i := range n {
|
||||
wg.Go(func() {
|
||||
if _, _, err := c.Cure(overrideIdent{pkg.ID{d, byte(i)}, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
cure: func(t *pkg.TContext) error {
|
||||
started.Done()
|
||||
<-t.Unwrap().Done()
|
||||
return stub.UniqueError(0xbad0 + i)
|
||||
},
|
||||
}}); !reflect.DeepEqual(err, stub.UniqueError(0xbad0+i)) {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}()
|
||||
if _, _, err := c.Cure(overrideIdent{pkg.ID{0xff}, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
cure: func(t *pkg.TContext) error {
|
||||
close(started)
|
||||
<-t.Unwrap().Done()
|
||||
return stub.UniqueError(0xbad)
|
||||
},
|
||||
}}); !reflect.DeepEqual(err, stub.UniqueError(0xbad)) {
|
||||
t.Fatalf("Cure: error = %v", err)
|
||||
started.Wait()
|
||||
}
|
||||
|
||||
blockCures(0xfd, 16)
|
||||
c.Abort()
|
||||
wg.Wait()
|
||||
|
||||
blockCures(0xff, 1)
|
||||
if !c.Cancel(unique.Make(pkg.ID{0xff})) {
|
||||
t.Fatal("missed cancellation")
|
||||
}
|
||||
wg.Wait()
|
||||
for c.Cancel(unique.Make(pkg.ID{0xff})) {
|
||||
}
|
||||
|
||||
c.Close()
|
||||
c.Abort()
|
||||
}, pkg.MustDecode("E4vEZKhCcL2gPZ2Tt59FS3lDng-d_2SKa2i5G_RbDfwGn6EemptFaGLPUDiOa94C")},
|
||||
|
||||
{"no assume checksum", 0, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
|
||||
|
||||
Reference in New Issue
Block a user