Skip to content

Commit

Permalink
Fix data race on request handling tests
Browse files Browse the repository at this point in the history
Signed-off-by: Luan Santos <lsantos@pivotal.io>
  • Loading branch information
julz authored and luan committed Nov 27, 2015
1 parent dcbb335 commit 518f19c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 46 deletions.
40 changes: 0 additions & 40 deletions fakes/fake_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ type FakeContainer struct {
result1 garden.CPULimits
result2 error
}
LimitDiskStub func(limits garden.DiskLimits) error
limitDiskMutex sync.RWMutex
limitDiskArgsForCall []struct {
limits garden.DiskLimits
}
limitDiskReturns struct {
result1 error
}
CurrentDiskLimitsStub func() (garden.DiskLimits, error)
currentDiskLimitsMutex sync.RWMutex
currentDiskLimitsArgsForCall []struct{}
Expand Down Expand Up @@ -457,38 +449,6 @@ func (fake *FakeContainer) CurrentCPULimitsReturns(result1 garden.CPULimits, res
}{result1, result2}
}

func (fake *FakeContainer) LimitDisk(limits garden.DiskLimits) error {
fake.limitDiskMutex.Lock()
fake.limitDiskArgsForCall = append(fake.limitDiskArgsForCall, struct {
limits garden.DiskLimits
}{limits})
fake.limitDiskMutex.Unlock()
if fake.LimitDiskStub != nil {
return fake.LimitDiskStub(limits)
} else {
return fake.limitDiskReturns.result1
}
}

func (fake *FakeContainer) LimitDiskCallCount() int {
fake.limitDiskMutex.RLock()
defer fake.limitDiskMutex.RUnlock()
return len(fake.limitDiskArgsForCall)
}

func (fake *FakeContainer) LimitDiskArgsForCall(i int) garden.DiskLimits {
fake.limitDiskMutex.RLock()
defer fake.limitDiskMutex.RUnlock()
return fake.limitDiskArgsForCall[i].limits
}

func (fake *FakeContainer) LimitDiskReturns(result1 error) {
fake.LimitDiskStub = nil
fake.limitDiskReturns = struct {
result1 error
}{result1}
}

func (fake *FakeContainer) CurrentDiskLimits() (garden.DiskLimits, error) {
fake.currentDiskLimitsMutex.Lock()
fake.currentDiskLimitsArgsForCall = append(fake.currentDiskLimitsArgsForCall, struct{}{})
Expand Down
12 changes: 6 additions & 6 deletions server/request_handling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,12 @@ var _ = Describe("When a client connects", func() {
})

Context("when a container has been created", func() {
var container garden.Container
var (
container garden.Container
graceTime time.Duration

var fakeContainer *fakes.FakeContainer
fakeContainer *fakes.FakeContainer
)

BeforeEach(func() {
fakeContainer = new(fakes.FakeContainer)
Expand Down Expand Up @@ -1251,15 +1254,12 @@ var _ = Describe("When a client connects", func() {
})

Describe("setting the grace time", func() {
var graceTime time.Duration

BeforeEach(func() {
graceTime = time.Second
serverBackend.GraceTimeReturns(graceTime)
})

It("destroys the container after it has been idle for the grace time", func() {
serverBackend.GraceTimeReturns(graceTime)

before := time.Now()
Ω(container.SetGraceTime(graceTime)).Should(Succeed())

Expand Down

0 comments on commit 518f19c

Please sign in to comment.