forked from rosa/hakurei
internal/pkg: drop cached error on cancel
This avoids disabling the artifact when using the individual cancel method. Unfortunately this makes the method blocking. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -194,6 +194,9 @@ func serve(
|
|||||||
}
|
}
|
||||||
|
|
||||||
case specialAbort:
|
case specialAbort:
|
||||||
|
if _err := conn.Close(); _err != nil {
|
||||||
|
log.Println(_err)
|
||||||
|
}
|
||||||
log.Println("aborting all pending cures")
|
log.Println("aborting all pending cures")
|
||||||
cm.c.Abort()
|
cm.c.Abort()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1120,7 +1120,7 @@ func (c *Cache) Done(id unique.Handle[ID]) <-chan struct{} {
|
|||||||
|
|
||||||
// Cancel cancels the ongoing cure of an [Artifact] referred to by the specified
|
// Cancel cancels the ongoing cure of an [Artifact] referred to by the specified
|
||||||
// identifier. Cancel returns whether the [context.CancelFunc] has been killed.
|
// identifier. Cancel returns whether the [context.CancelFunc] has been killed.
|
||||||
// Cancel does not wait for the cure to complete.
|
// Cancel returns after the cure is complete.
|
||||||
func (c *Cache) Cancel(id unique.Handle[ID]) bool {
|
func (c *Cache) Cancel(id unique.Handle[ID]) bool {
|
||||||
c.identMu.RLock()
|
c.identMu.RLock()
|
||||||
pending, ok := c.identPending[id]
|
pending, ok := c.identPending[id]
|
||||||
@@ -1129,6 +1129,13 @@ func (c *Cache) Cancel(id unique.Handle[ID]) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
pending.cancel()
|
pending.cancel()
|
||||||
|
<-pending.done
|
||||||
|
|
||||||
|
c.abortMu.Lock()
|
||||||
|
c.identMu.Lock()
|
||||||
|
delete(c.identErr, id)
|
||||||
|
c.identMu.Unlock()
|
||||||
|
c.abortMu.Unlock()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -911,7 +911,7 @@ func TestCache(t *testing.T) {
|
|||||||
var started sync.WaitGroup
|
var started sync.WaitGroup
|
||||||
defer started.Wait()
|
defer started.Wait()
|
||||||
|
|
||||||
blockCures := func(d byte, n int) {
|
blockCures := func(d byte, e stub.UniqueError, n int) {
|
||||||
started.Add(n)
|
started.Add(n)
|
||||||
for i := range n {
|
for i := range n {
|
||||||
wg.Go(func() {
|
wg.Go(func() {
|
||||||
@@ -920,9 +920,9 @@ func TestCache(t *testing.T) {
|
|||||||
cure: func(t *pkg.TContext) error {
|
cure: func(t *pkg.TContext) error {
|
||||||
started.Done()
|
started.Done()
|
||||||
<-t.Unwrap().Done()
|
<-t.Unwrap().Done()
|
||||||
return stub.UniqueError(0xbad0 + i)
|
return e + stub.UniqueError(i)
|
||||||
},
|
},
|
||||||
}}); !reflect.DeepEqual(err, stub.UniqueError(0xbad0+i)) {
|
}}); !reflect.DeepEqual(err, e+stub.UniqueError(i)) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -930,15 +930,26 @@ func TestCache(t *testing.T) {
|
|||||||
started.Wait()
|
started.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
blockCures(0xfd, 16)
|
blockCures(0xfd, 0xbad, 16)
|
||||||
c.Abort()
|
c.Abort()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
blockCures(0xff, 1)
|
blockCures(0xfd, 0xcafe, 16)
|
||||||
|
c.Abort()
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
blockCures(0xff, 0xbad, 1)
|
||||||
if !c.Cancel(unique.Make(pkg.ID{0xff})) {
|
if !c.Cancel(unique.Make(pkg.ID{0xff})) {
|
||||||
t.Fatal("missed cancellation")
|
t.Fatal("missed cancellation")
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
|
blockCures(0xff, 0xcafe, 1)
|
||||||
|
if !c.Cancel(unique.Make(pkg.ID{0xff})) {
|
||||||
|
t.Fatal("missed cancellation")
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
for c.Cancel(unique.Make(pkg.ID{0xff})) {
|
for c.Cancel(unique.Make(pkg.ID{0xff})) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user