aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/pkg_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-04-17 22:39:56 +0900
committerOphestra <cat@gensokyo.uk>2026-04-17 22:40:35 +0900
commit30a9dfa4b84859a38af8a149f4ce3ea8f69a7001 (patch)
tree2b51eb7acb761f6700b8a59f328dfe5e79caf4b3 /internal/pkg/pkg_test.go
parent8d657b6fdf5570e3c0324ec5086ee8aad88171ac (diff)
internal/pkg: abort all pending cures
This cancels all current pending cures without closing the cache. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/pkg_test.go')
-rw-r--r--internal/pkg/pkg_test.go53
1 files changed, 37 insertions, 16 deletions
diff --git a/internal/pkg/pkg_test.go b/internal/pkg/pkg_test.go
index dbaa0801..3110ed06 100644
--- a/internal/pkg/pkg_test.go
+++ b/internal/pkg/pkg_test.go
@@ -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) {