Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing concurrent test on Windows #1890

Merged
merged 8 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/oci/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
"syscall"
"time"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions pkg/oci/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"runtime"
"sort"
"strings"
"sync"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}()

Expand All @@ -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 {
Expand Down
Loading