Skip to content

Commit

Permalink
Merge pull request #9736 from csrwng/fix_imageprogress_test_race
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Jul 8, 2016
2 parents 1d2a238 + bffe3c3 commit 69bd399
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions pkg/util/docker/dockerfile/builder/imageprogress/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"io"
"reflect"
"sync"
"testing"
)

Expand Down Expand Up @@ -123,17 +124,40 @@ func TestErrorOnCopy(t *testing.T) {
}
}

type syncedReport struct {
r report
m *sync.Mutex
}

func newSyncedReport() *syncedReport {
return &syncedReport{
m: &sync.Mutex{},
}
}

func (s *syncedReport) set(r report) {
s.m.Lock()
defer s.m.Unlock()
s.r = r
}

func (s *syncedReport) get() report {
s.m.Lock()
defer s.m.Unlock()
return s.r
}

func TestStableLayerCount(t *testing.T) {
var result report
w := newWriter(func(r report) { result = r }, func(a, b report) bool { return true })
result := newSyncedReport()
w := newWriter(func(r report) { result.set(r) }, func(a, b report) bool { return true })
w.(*imageProgressWriter).stableThreshhold = 3 // This means that the number of layers must be stable for at least 3 lines
p := newProgressGenerator(w)

// Increase number of layers by one each time
p.status("1", "one")
p.status("2", "two")
p.status("3", "three")
if result != nil {
if result.get() != nil {
t.Errorf("do not expect any reports at this point")
return
}
Expand All @@ -146,7 +170,7 @@ func TestStableLayerCount(t *testing.T) {
expected := report{
statusPending: &layerDetail{Count: 3},
}
if !compareReport(result, expected) {
if !compareReport(result.get(), expected) {
t.Errorf("did not get expected report")
}
}
Expand Down

0 comments on commit 69bd399

Please sign in to comment.