Keep in-flight work across concurrent Deploys
This commit is contained in:
@@ -229,7 +229,14 @@ func (d *Deployer) Deploy(ctx context.Context, only []string, modules bool) erro
|
||||
want[e] = true
|
||||
}
|
||||
d.mu.Lock()
|
||||
clear(d.flights)
|
||||
maps.DeleteFunc(d.flights, func(_ string, f *flight) bool {
|
||||
select {
|
||||
case <-f.done:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
clear(d.skips)
|
||||
clear(d.counts)
|
||||
d.mu.Unlock()
|
||||
|
||||
@@ -15,9 +15,11 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -1364,3 +1366,38 @@ func TestCorrectedBranchCollisionSkipsAll(t *testing.T) {
|
||||
t.Fatal("collision must not block other envs")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConcurrentDeploySharesInFlightFetch(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
commit(t, f.control, map[string]string{"Puppetfile": f.puppetfile()})
|
||||
d := f.deployer()
|
||||
var srcFetches, modFetches atomic.Int32
|
||||
bStarted := make(chan struct{})
|
||||
var once sync.Once
|
||||
d.runGit = func(ctx context.Context, dir string, args ...string) (string, error) {
|
||||
if slices.Contains(args, "fetch") {
|
||||
switch {
|
||||
case slices.Contains(args, f.control):
|
||||
if srcFetches.Add(1) == 2 {
|
||||
once.Do(func() { close(bStarted) })
|
||||
}
|
||||
case slices.Contains(args, f.mod):
|
||||
if modFetches.Add(1) == 1 {
|
||||
<-bStarted
|
||||
}
|
||||
}
|
||||
}
|
||||
return runGit(ctx, dir, args...)
|
||||
}
|
||||
errc := make(chan error, 2)
|
||||
go func() { errc <- d.Deploy(context.Background(), nil, false) }()
|
||||
for modFetches.Load() == 0 {
|
||||
runtime.Gosched()
|
||||
}
|
||||
go func() { errc <- d.Deploy(context.Background(), nil, false) }()
|
||||
<-errc
|
||||
<-errc
|
||||
if n := modFetches.Load(); n != 1 {
|
||||
t.Fatalf("module mirror fetched %d times; the second Deploy dropped the first's in-flight fetch", n)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user