Skip to content

Commit

Permalink
fix: wait for both builds
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Vasek <[email protected]>
  • Loading branch information
matejvasek committed Jul 26, 2023
1 parent 3208508 commit ff7bd71
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 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,10 +94,9 @@ 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 {
t.Errorf("test build error %v", err)
}
Expand All @@ -110,7 +110,9 @@ func TestBuilder_Concurrency(t *testing.T) {
builder2.buildFn = func(config *buildConfig, platform v1.Platform) (v1.Descriptor, v1.Layer, error) {
return v1.Descriptor{}, nil, fmt.Errorf("should not have been invoked")
}
wg.Add(1)
go func() {
wg.Done()
err = builder2.Build(context.Background(), f, TestPlatforms)
if !errors.As(err, &ErrBuildInProgress{}) {
t.Errorf("test build error %v", err)
Expand All @@ -119,7 +121,7 @@ func TestBuilder_Concurrency(t *testing.T) {

// Release the blocking Build A and wait until complete.
continueCh <- true
<-doneCh
wg.Done()
}

func isFirstBuild(cfg *buildConfig, current v1.Platform) bool {
Expand Down

0 comments on commit ff7bd71

Please sign in to comment.