浏览代码

Fix flaky test TestSuccessfulDownload

One of the things this test checks is that the progress indicator
completes for each download. Some progress messages may be lost because
only one message is buffered for each download, but the last progress
message is guaranteed not to be lost. The test therefore checks for a
10/10 progress indication.

However, the assumption that this is the last progress message to be
sent is incorrect. The last message is actually "Pull complete". So
check for this instead.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Aaron Lehmann 9 年之前
父节点
当前提交
0757a52737
共有 1 个文件被更改,包括 6 次插入10 次删除
  1. 6 10
      distribution/xfer/download_test.go

+ 6 - 10
distribution/xfer/download_test.go

@@ -250,15 +250,11 @@ func TestSuccessfulDownload(t *testing.T) {
 
 	progressChan := make(chan progress.Progress)
 	progressDone := make(chan struct{})
-	receivedProgress := make(map[string]int64)
+	receivedProgress := make(map[string]progress.Progress)
 
 	go func() {
 		for p := range progressChan {
-			if p.Action == "Downloading" {
-				receivedProgress[p.ID] = p.Current
-			} else if p.Action == "Already exists" {
-				receivedProgress[p.ID] = -1
-			}
+			receivedProgress[p.ID] = p
 		}
 		close(progressDone)
 	}()
@@ -293,11 +289,11 @@ func TestSuccessfulDownload(t *testing.T) {
 		descriptor := d.(*mockDownloadDescriptor)
 
 		if descriptor.diffID != "" {
-			if receivedProgress[d.ID()] != -1 {
-				t.Fatalf("did not get 'already exists' message for %v", d.ID())
+			if receivedProgress[d.ID()].Action != "Already exists" {
+				t.Fatalf("did not get 'Already exists' message for %v", d.ID())
 			}
-		} else if receivedProgress[d.ID()] != 10 {
-			t.Fatalf("missing or wrong progress output for %v (got: %d)", d.ID(), receivedProgress[d.ID()])
+		} else if receivedProgress[d.ID()].Action != "Pull complete" {
+			t.Fatalf("did not get 'Pull complete' message for %v", d.ID())
 		}
 
 		if rootFS.DiffIDs[i] != descriptor.expectedDiffID {