Skip to content

Commit

Permalink
Fix failing concurrent test on Windows (knative#1890)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
matejvasek committed Sep 27, 2023
1 parent 46e02f4 commit 3742481
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
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

0 comments on commit 3742481

Please sign in to comment.