From 24fe6d36fa07787df3962c40bb299a1aab8f441c Mon Sep 17 00:00:00 2001 From: Matej Vasek Date: Fri, 28 Jul 2023 03:03:08 +0200 Subject: [PATCH] Fix failing concurrent test on Windows (#1890) * src: better debugging Signed-off-by: Matej Vasek * fix: wait for both builds Signed-off-by: Matej Vasek * fixup Signed-off-by: Matej Vasek * fixup Signed-off-by: Matej Vasek * fixup Signed-off-by: Matej Vasek * fix: detection of process liveness on Windows Signed-off-by: Matej Vasek * fix: make symlink relative Signed-off-by: Matej Vasek * fixup: cleanup Signed-off-by: Matej Vasek --------- Signed-off-by: Matej Vasek --- pkg/oci/builder.go | 10 +++++++++- pkg/oci/builder_test.go | 19 ++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/pkg/oci/builder.go b/pkg/oci/builder.go index ad56e99bf2..de7f55ac30 100644 --- a/pkg/oci/builder.go +++ b/pkg/oci/builder.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "strconv" "syscall" "time" @@ -235,6 +236,9 @@ func processExists(pid string) bool { if err != nil { return false } + if runtime.GOOS == "windows" { + return true + } err = process.Signal(syscall.Signal(0)) return err == nil } @@ -276,7 +280,11 @@ func updateLastLink(cfg *buildConfig) error { fmt.Printf("ln -s %v %v\n", cfg.buildDir(), cfg.lastLink()) } _ = os.RemoveAll(cfg.lastLink()) - return os.Symlink(cfg.buildDir(), cfg.lastLink()) + rp, err := filepath.Rel(filepath.Dir(cfg.lastLink()), cfg.buildDir()) + if err != nil { + return err + } + return os.Symlink(rp, cfg.lastLink()) } // toPlatforms converts func's implementation-agnostic Platform struct diff --git a/pkg/oci/builder_test.go b/pkg/oci/builder_test.go index fdcfc6ff69..eb4086fc9b 100644 --- a/pkg/oci/builder_test.go +++ b/pkg/oci/builder_test.go @@ -14,6 +14,7 @@ import ( "runtime" "sort" "strings" + "sync" "testing" "github.com/google/go-cmp/cmp" @@ -81,7 +82,7 @@ func TestBuilder_Concurrency(t *testing.T) { var ( pausedCh = make(chan bool) continueCh = make(chan bool) - doneCh = make(chan bool) + wg sync.WaitGroup ) // Build A @@ -93,12 +94,11 @@ func TestBuilder_Concurrency(t *testing.T) { } return } - builder1.onDone = func() { - doneCh <- true // Notify of being done - } + wg.Add(1) go func() { + defer wg.Done() if err := builder1.Build(context.Background(), f, TestPlatforms); err != nil { - fmt.Fprintf(os.Stderr, "test build error %v", err) + t.Errorf("test build error: %v", err) } }() @@ -107,16 +107,21 @@ func TestBuilder_Concurrency(t *testing.T) { // Build B builder2 := NewBuilder("builder2", true) + builder2.buildFn = func(config *buildConfig, platform v1.Platform) (v1.Descriptor, v1.Layer, error) { + return v1.Descriptor{}, nil, fmt.Errorf("the buildFn should not have been invoked") + } + wg.Add(1) go func() { + defer wg.Done() err = builder2.Build(context.Background(), f, TestPlatforms) if !errors.As(err, &ErrBuildInProgress{}) { - fmt.Fprintf(os.Stderr, "test build error %v", err) + t.Errorf("test build error: %v", err) } }() // Release the blocking Build A and wait until complete. continueCh <- true - <-doneCh + wg.Wait() } func isFirstBuild(cfg *buildConfig, current v1.Platform) bool {