diff options
Diffstat (limited to 'internal/pkg/pkg_test.go')
| -rw-r--r-- | internal/pkg/pkg_test.go | 53 |
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) { |
