| 2201 | } |
| 2202 | |
| 2203 | func TestAfterTotalWaitTimeWhileExecution(t *testing.T) { |
| 2204 | t.Parallel() |
| 2205 | |
| 2206 | waitDuration := 1 |
| 2207 | total, waitMs := 5, time.Millisecond*time.Duration(waitDuration) |
| 2208 | aTimer := new(timer) |
| 2209 | for i := 0; i < total; i++ { |
| 2210 | aTimer.On("GetTime", i).After(waitMs).Return(fmt.Sprintf("Time%d", i)).Once() |
| 2211 | } |
| 2212 | time.Sleep(waitMs) |
| 2213 | start := time.Now() |
| 2214 | var results []string |
| 2215 | |
| 2216 | for i := 0; i < total; i++ { |
| 2217 | results = append(results, aTimer.GetTime(i)) |
| 2218 | } |
| 2219 | |
| 2220 | end := time.Now() |
| 2221 | elapsedTime := end.Sub(start) |
| 2222 | assert.True(t, elapsedTime > waitMs, fmt.Sprintf("Total elapsed time:%v should be at least greater than %v", elapsedTime, waitMs)) |
| 2223 | assert.Equal(t, total, len(results)) |
| 2224 | for i := range results { |
| 2225 | assert.Equal(t, fmt.Sprintf("Time%d", i), results[i], "Return value of method should be same") |
| 2226 | } |
| 2227 | } |
| 2228 | |
| 2229 | func TestArgumentMatcherToPrintMismatch(t *testing.T) { |
| 2230 | t.Parallel() |