shad-go/distbuild/disttest/three_workers_test.go

66 lines
1.3 KiB
Go
Raw Normal View History

2020-04-05 12:00:33 +00:00
package disttest
import (
"fmt"
"os"
"sync"
"testing"
"github.com/stretchr/testify/assert"
2023-04-26 12:29:27 +00:00
"github.com/stretchr/testify/require"
2020-04-05 12:00:33 +00:00
"gitlab.com/slon/shad-go/distbuild/pkg/build"
)
var threeWorkerConfig = &Config{WorkerCount: 3}
func TestArtifactTransferBetweenWorkers(t *testing.T) {
env, cancel := newEnv(t, threeWorkerConfig)
defer cancel()
baseJob := build.Job{
ID: build.ID{'a'},
Name: "write",
Cmds: []build.Cmd{
{CatTemplate: "OK", CatOutput: "{{.OutputDir}}/out.txt"},
},
}
var wg sync.WaitGroup
wg.Add(3)
for i := 0; i < 3; i++ {
depJobID := build.ID{'b', byte(i)}
depJob := build.Job{
ID: depJobID,
Name: "cat",
Cmds: []build.Cmd{
{Exec: []string{"cat", fmt.Sprintf("{{index .Deps %q}}/out.txt", build.ID{'a'})}},
{Exec: []string{"sleep", "1"}, Environ: os.Environ()}, // DepTimeout is 100ms.
},
Deps: []build.ID{{'a'}},
}
graph := build.Graph{Jobs: []build.Job{baseJob, depJob}}
go func() {
defer wg.Done()
recorder := NewRecorder()
if !assert.NoError(t, env.Client.Build(env.Ctx, graph, recorder)) {
return
}
assert.Len(t, recorder.Jobs, 2)
assert.Equal(t, &JobResult{Stdout: "OK", Code: new(int)}, recorder.Jobs[depJobID])
}()
}
wg.Wait()
2023-04-26 12:29:27 +00:00
for _, cache := range env.WorkerCache {
_, unlock, err := cache.Get(baseJob.ID)
require.NoError(t, err)
defer unlock()
}
2020-04-05 12:00:33 +00:00
}