mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
572ce80230
This commit adds a transfer manager which deduplicates and schedules transfers, and also an upload manager and download manager that build on top of the transfer manager to provide high-level interfaces for uploads and downloads. The push and pull code is modified to use these building blocks. Some benefits of the changes: - Simplification of push/pull code - Pushes can upload layers concurrently - Failed downloads and uploads are retried after backoff delays - Cancellation is supported, but individual transfers will only be cancelled if all pushes or pulls using them are cancelled. - The distribution code is decoupled from Docker Engine packages and API conventions (i.e. streamformatter), which will make it easier to split out. This commit also includes unit tests for the new distribution/xfer package. The tests cover 87.8% of the statements in the package. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
75 lines
1.3 KiB
Go
75 lines
1.3 KiB
Go
package progress
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"io/ioutil"
|
|
"testing"
|
|
)
|
|
|
|
func TestOutputOnPrematureClose(t *testing.T) {
|
|
content := []byte("TESTING")
|
|
reader := ioutil.NopCloser(bytes.NewReader(content))
|
|
progressChan := make(chan Progress, 10)
|
|
|
|
pr := NewProgressReader(reader, ChanOutput(progressChan), int64(len(content)), "Test", "Read")
|
|
|
|
part := make([]byte, 4, 4)
|
|
_, err := io.ReadFull(pr, part)
|
|
if err != nil {
|
|
pr.Close()
|
|
t.Fatal(err)
|
|
}
|
|
|
|
drainLoop:
|
|
for {
|
|
select {
|
|
case <-progressChan:
|
|
default:
|
|
break drainLoop
|
|
}
|
|
}
|
|
|
|
pr.Close()
|
|
|
|
select {
|
|
case <-progressChan:
|
|
default:
|
|
t.Fatalf("Expected some output when closing prematurely")
|
|
}
|
|
}
|
|
|
|
func TestCompleteSilently(t *testing.T) {
|
|
content := []byte("TESTING")
|
|
reader := ioutil.NopCloser(bytes.NewReader(content))
|
|
progressChan := make(chan Progress, 10)
|
|
|
|
pr := NewProgressReader(reader, ChanOutput(progressChan), int64(len(content)), "Test", "Read")
|
|
|
|
out, err := ioutil.ReadAll(pr)
|
|
if err != nil {
|
|
pr.Close()
|
|
t.Fatal(err)
|
|
}
|
|
if string(out) != "TESTING" {
|
|
pr.Close()
|
|
t.Fatalf("Unexpected output %q from reader", string(out))
|
|
}
|
|
|
|
drainLoop:
|
|
for {
|
|
select {
|
|
case <-progressChan:
|
|
default:
|
|
break drainLoop
|
|
}
|
|
}
|
|
|
|
pr.Close()
|
|
|
|
select {
|
|
case <-progressChan:
|
|
t.Fatalf("Should have closed silently when read is complete")
|
|
default:
|
|
}
|
|
}
|