mirror of https://github.com/knative/func.git
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:
parent
0d6e210673
commit
24fe6d36fa
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue