Skip to content

Commit

Permalink
Fixing comments: reduced test time, locking in after, unexported wait…
Browse files Browse the repository at this point in the history
…Time

- WaitUntil/After overrides each other value
- currently if channel is set that takes the priority, if not the
  waitTime is used to Sleep
  • Loading branch information
Dinesh Kumar committed Dec 30, 2017
1 parent a7101ec commit cda9361
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ _testmain.go
*.exe

.DS_Store
*.swp
9 changes: 6 additions & 3 deletions mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Call struct {
// receives a message or is closed. nil means it returns immediately.
WaitFor <-chan time.Time

WaitTime time.Duration
waitTime time.Duration

// Holds a handler used to manipulate arguments content that are passed by
// reference. It's useful when mocking methods such as unmarshalers or
Expand Down Expand Up @@ -132,7 +132,9 @@ func (c *Call) WaitUntil(w <-chan time.Time) *Call {
//
// Mock.On("MyMethod", arg1, arg2).After(time.Second)
func (c *Call) After(d time.Duration) *Call {
c.WaitTime = d
c.lock()
defer c.unlock()
c.waitTime = d
return c
}

Expand Down Expand Up @@ -331,8 +333,9 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen
// block if specified
if call.WaitFor != nil {
<-call.WaitFor
} else {
time.Sleep(call.waitTime)
}
time.Sleep(call.WaitTime)

m.mutex.Lock()
runFn := call.RunFn
Expand Down
11 changes: 1 addition & 10 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ func (s *timer) GetTime(i int) string {
}

func TestAfterTotalWaitTimeWhileExecution(t *testing.T) {
waitDuration := 500
waitDuration := 10
total, waitMs := 5, time.Millisecond*time.Duration(waitDuration)
aTimer := new(timer)
for i := 0; i < total; i++ {
Expand All @@ -1252,15 +1252,6 @@ func TestAfterTotalWaitTimeWhileExecution(t *testing.T) {
}
}

func TestAfterWaitTimeDuration(t *testing.T) {
aTimer := new(timer)
waitDuration := time.Second

call := aTimer.On("GetTime", 1).After(waitDuration).Return("Time1").Once()

assert.Equal(t, waitDuration, call.WaitTime, "After should update call.WaitTime")
}

func ConcurrencyTestMethod(m *Mock) {
m.Called()
}

0 comments on commit cda9361

Please # to comment.