fix: stream platform builder progress
This commit is contained in:
@@ -19,6 +19,12 @@ type captureDistributionBuilder struct {
|
||||
payload []byte
|
||||
}
|
||||
|
||||
type progressDistributionBuilder struct {
|
||||
started chan struct{}
|
||||
release <-chan struct{}
|
||||
payload []byte
|
||||
}
|
||||
|
||||
func (builder captureDistributionBuilder) Readiness() (bool, string) {
|
||||
return true, ""
|
||||
}
|
||||
@@ -31,6 +37,27 @@ func (builder captureDistributionBuilder) Build(input domain.DistributionBuildIn
|
||||
return domain.CopyBytes(builder.payload), nil
|
||||
}
|
||||
|
||||
func (builder progressDistributionBuilder) Readiness() (bool, string) {
|
||||
return true, ""
|
||||
}
|
||||
|
||||
func (builder progressDistributionBuilder) Build(input domain.DistributionBuildInput) ([]byte, error) {
|
||||
return builder.BuildWithProgress(input, nil)
|
||||
}
|
||||
|
||||
func (builder progressDistributionBuilder) BuildWithProgress(_ domain.DistributionBuildInput, progress func(DistributionBuildProgress)) ([]byte, error) {
|
||||
if progress != nil {
|
||||
progress(DistributionBuildProgress{Percent: 72, Message: "build_compile: compiling run target executable"})
|
||||
}
|
||||
if builder.started != nil {
|
||||
builder.started <- struct{}{}
|
||||
}
|
||||
if builder.release != nil {
|
||||
<-builder.release
|
||||
}
|
||||
return domain.CopyBytes(builder.payload), nil
|
||||
}
|
||||
|
||||
func TestCoreServiceKeepsPlatformBuildKeyOffMachineJobChannel(t *testing.T) {
|
||||
svc, session, instance := newDistributionTestFixture(t)
|
||||
plugin, err := svc.store.GamePlugins().Get(instance.PluginID)
|
||||
@@ -319,6 +346,39 @@ func TestCoreServiceDoesNotDuplicateInFlightPlatformBuild(t *testing.T) {
|
||||
completeDistributionBuild(t, svc, first, nil)
|
||||
}
|
||||
|
||||
func TestCoreServiceProjectsPlatformBuilderProgressBeforeCompletion(t *testing.T) {
|
||||
svc, session, instance := newDistributionTestFixture(t)
|
||||
started := make(chan struct{}, 1)
|
||||
release := make(chan struct{})
|
||||
var releaseOnce sync.Once
|
||||
t.Cleanup(func() { releaseOnce.Do(func() { close(release) }) })
|
||||
svc.ConfigureDistributionBuilder(progressDistributionBuilder{started: started, release: release, payload: []byte("progress-platform-build")})
|
||||
|
||||
distribution, err := svc.GenerateRunDistributionForSession(session, domain.RunDistributionGenerateRequest{
|
||||
ServerInstanceID: instance.ID,
|
||||
TargetOS: "linux",
|
||||
TargetArch: "amd64",
|
||||
IdempotencyKey: "platform-builder-progress",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("generate platform distribution: %v", err)
|
||||
}
|
||||
select {
|
||||
case <-started:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("platform builder did not report progress")
|
||||
}
|
||||
job, err := svc.GetJob(distribution.BuildJobID)
|
||||
if err != nil {
|
||||
t.Fatalf("get progress job: %v", err)
|
||||
}
|
||||
if job.State != domain.JobStateRunning || job.Progress.Percent != 72 || job.Progress.Message != "build_compile: compiling run target executable" {
|
||||
t.Fatalf("expected in-flight platform builder progress, got %+v", job)
|
||||
}
|
||||
releaseOnce.Do(func() { close(release) })
|
||||
completeDistributionBuild(t, svc, distribution, nil)
|
||||
}
|
||||
|
||||
func TestCoreServiceDiscardsBuildCompletedAfterKeyReset(t *testing.T) {
|
||||
svc, session, instance := newDistributionTestFixture(t)
|
||||
inputs := make(chan domain.DistributionBuildInput, 1)
|
||||
|
||||
Reference in New Issue
Block a user