Fix failing concurrent test on Windows (#1890)

* src: better debugging

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fix: wait for both builds

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fix: detection of process liveness on Windows

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fix: make symlink relative

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup: cleanup

Signed-off-by: Matej Vasek <mvasek@redhat.com>

---------

Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
Matej Vasek 2023-07-28 03:03:08 +02:00 committed by GitHub
parent 0d6e210673
commit 24fe6d36fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 8 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"strconv" "strconv"
"syscall" "syscall"
"time" "time"
@ -235,6 +236,9 @@ func processExists(pid string) bool {
if err != nil { if err != nil {
return false return false
} }
if runtime.GOOS == "windows" {
return true
}
err = process.Signal(syscall.Signal(0)) err = process.Signal(syscall.Signal(0))
return err == nil return err == nil
} }
@ -276,7 +280,11 @@ func updateLastLink(cfg *buildConfig) error {
fmt.Printf("ln -s %v %v\n", cfg.buildDir(), cfg.lastLink()) fmt.Printf("ln -s %v %v\n", cfg.buildDir(), cfg.lastLink())
} }
_ = os.RemoveAll(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 // toPlatforms converts func's implementation-agnostic Platform struct

View File

@ -14,6 +14,7 @@ import (
"runtime" "runtime"
"sort" "sort"
"strings" "strings"
"sync"
"testing" "testing"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
@ -81,7 +82,7 @@ func TestBuilder_Concurrency(t *testing.T) {
var ( var (
pausedCh = make(chan bool) pausedCh = make(chan bool)
continueCh = make(chan bool) continueCh = make(chan bool)
doneCh = make(chan bool) wg sync.WaitGroup
) )
// Build A // Build A
@ -93,12 +94,11 @@ func TestBuilder_Concurrency(t *testing.T) {
} }
return return
} }
builder1.onDone = func() { wg.Add(1)
doneCh <- true // Notify of being done
}
go func() { go func() {
defer wg.Done()
if err := builder1.Build(context.Background(), f, TestPlatforms); err != nil { 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 // Build B
builder2 := NewBuilder("builder2", true) 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() { go func() {
defer wg.Done()
err = builder2.Build(context.Background(), f, TestPlatforms) err = builder2.Build(context.Background(), f, TestPlatforms)
if !errors.As(err, &ErrBuildInProgress{}) { 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. // Release the blocking Build A and wait until complete.
continueCh <- true continueCh <- true
<-doneCh wg.Wait()
} }
func isFirstBuild(cfg *buildConfig, current v1.Platform) bool { func isFirstBuild(cfg *buildConfig, current v1.Platform) bool {