Merge pull request #6294 from thaJeztah/28.x_backport_progress_test

[28.x] cli/command/container: TestRunPullTermination: rewrite with streamformatter
This commit is contained in:
Sebastiaan van Stijn 2025-08-19 13:04:32 +02:00 committed by GitHub
commit 4313a2bbb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 14 deletions

View File

@ -2,9 +2,7 @@ package container
import ( import (
"context" "context"
"encoding/json"
"errors" "errors"
"fmt"
"io" "io"
"net" "net"
"syscall" "syscall"
@ -20,7 +18,8 @@ import (
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
ocispec "github.com/opencontainers/image-spec/specs-go/v1" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
@ -242,23 +241,19 @@ func TestRunPullTermination(t *testing.T) {
_ = server.Close() _ = server.Close()
}) })
go func() { go func() {
enc := json.NewEncoder(server) id := test.RandomID()[:12] // short-ID
progressOutput := streamformatter.NewJSONProgressOutput(server, true)
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
select { select {
case <-ctx.Done(): case <-ctx.Done():
assert.NilError(t, server.Close(), "failed to close imageCreateFunc server") assert.NilError(t, server.Close(), "failed to close imageCreateFunc server")
return return
default: default:
assert.NilError(t, enc.Encode(jsonmessage.JSONMessage{ assert.NilError(t, progressOutput.WriteProgress(progress.Progress{
Status: "Downloading", ID: id,
ID: fmt.Sprintf("id-%d", i), Message: "Downloading",
TimeNano: time.Now().UnixNano(), Current: int64(i),
Time: time.Now().Unix(), Total: 100,
Progress: &jsonmessage.JSONProgress{
Current: int64(i),
Total: 100,
Start: 0,
},
})) }))
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
} }