1
0
forked from rosa/hakurei

cmd/mbf: do not abort cache acquisition during testing

This can sometimes fire during testing due to how short the test is.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-04-17 02:06:51 +09:00
parent 9daba60809
commit a394971dd7
3 changed files with 62 additions and 72 deletions

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"os" "os"
"path/filepath" "path/filepath"
"testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/internal/pkg" "hakurei.app/internal/pkg"
@@ -53,6 +54,9 @@ func (cache *cache) open() (err error) {
go func() { go func() {
select { select {
case <-cache.ctx.Done(): case <-cache.ctx.Done():
if testing.Testing() {
return
}
os.Exit(2) os.Exit(2)
case <-done: case <-done:

View File

@@ -1,7 +1,6 @@
package main package main
import ( import (
"context"
"log" "log"
"os" "os"
"testing" "testing"
@@ -14,7 +13,7 @@ func TestCache(t *testing.T) {
t.Parallel() t.Parallel()
cm := cache{ cm := cache{
ctx: context.Background(), ctx: t.Context(),
msg: message.New(log.New(os.Stderr, "check: ", 0)), msg: message.New(log.New(os.Stderr, "check: ", 0)),
base: t.TempDir(), base: t.TempDir(),

View File

@@ -164,17 +164,15 @@ func main() {
func(args []string) (err error) { func(args []string) (err error) {
return commandInfo(&cm, args, os.Stdout, flagStatus, flagReport) return commandInfo(&cm, args, os.Stdout, flagStatus, flagReport)
}, },
). ).Flag(
Flag( &flagStatus,
&flagStatus, "status", command.BoolFlag(false),
"status", command.BoolFlag(false), "Display cure status if available",
"Display cure status if available", ).Flag(
). &flagReport,
Flag( "report", command.StringFlag(""),
&flagReport, "Load cure status from this report file instead of cache",
"report", command.StringFlag(""), )
"Load cure status from this report file instead of cache",
)
} }
c.NewCommand( c.NewCommand(
@@ -273,12 +271,11 @@ func main() {
" package(s) are out of date")) " package(s) are out of date"))
} }
return errors.Join(errs...) return errors.Join(errs...)
}). }).Flag(
Flag( &flagJobs,
&flagJobs, "j", command.IntFlag(32),
"j", command.IntFlag(32), "Maximum number of simultaneous connections",
"Maximum number of simultaneous connections", )
)
} }
c.NewCommand( c.NewCommand(
@@ -378,22 +375,19 @@ func main() {
return return
}, },
). ).Flag(
Flag( &flagGentoo,
&flagGentoo, "gentoo", command.StringFlag(""),
"gentoo", command.StringFlag(""), "Bootstrap from a Gentoo stage3 tarball",
"Bootstrap from a Gentoo stage3 tarball", ).Flag(
). &flagChecksum,
Flag( "checksum", command.StringFlag(""),
&flagChecksum, "Checksum of Gentoo stage3 tarball",
"checksum", command.StringFlag(""), ).Flag(
"Checksum of Gentoo stage3 tarball", &flagStage0,
). "stage0", command.BoolFlag(false),
Flag( "Create bootstrap stage0 tarball",
&flagStage0, )
"stage0", command.BoolFlag(false),
"Create bootstrap stage0 tarball",
)
} }
{ {
@@ -487,27 +481,23 @@ func main() {
return err return err
} }
}, },
). ).Flag(
Flag( &flagDump,
&flagDump, "dump", command.StringFlag(""),
"dump", command.StringFlag(""), "Write IR to specified pathname and terminate",
"Write IR to specified pathname and terminate", ).Flag(
). &flagExport,
Flag( "export", command.StringFlag(""),
&flagExport, "Export cured artifact to specified pathname",
"export", command.StringFlag(""), ).Flag(
"Export cured artifact to specified pathname", &flagEnter,
). "enter", command.BoolFlag(false),
Flag( "Enter cure container with an interactive shell",
&flagEnter, ).Flag(
"enter", command.BoolFlag(false), &flagRemote,
"Enter cure container with an interactive shell", "daemon", command.BoolFlag(false),
). "Cure artifact on the daemon",
Flag( )
&flagRemote,
"daemon", command.BoolFlag(false),
"Cure artifact on the daemon",
)
} }
{ {
@@ -647,22 +637,19 @@ func main() {
} }
return z.Wait() return z.Wait()
}, },
). ).Flag(
Flag( &flagNet,
&flagNet, "net", command.BoolFlag(false),
"net", command.BoolFlag(false), "Share host net namespace",
"Share host net namespace", ).Flag(
). &flagSession,
Flag( "session", command.BoolFlag(true),
&flagSession, "Retain session",
"session", command.BoolFlag(true), ).Flag(
"Retain session", &flagWithToolchain,
). "with-toolchain", command.BoolFlag(false),
Flag( "Include the stage2 LLVM toolchain",
&flagWithToolchain, )
"with-toolchain", command.BoolFlag(false),
"Include the stage2 LLVM toolchain",
)
} }