New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 642161 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Aug 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug



Sign in to add a comment

Can't mock time.time() because expect_tests will go into an infinite loop

Project Member Reported by ta...@google.com, Aug 29 2016

Issue description

Hello!

I am working on ts_mon within infra_libs. And I've found out that we cannot mock time.time().

My test run would go into an infinite loop and print '???...UNKNOWN ERROR' like thousands of times, even though we have only 200 tests.

I wonder if anyone knows how to fix this.

Mocking time.time() would be super convenient for us.
 
What specific problem are you having?

interface_test mocks time.time like this: https://cs.chromium.org/chromium/infra/packages/infra_libs/infra_libs/ts_mon/common/test/interface_test.py?q=interface_test.py&sq=package:chromium&dr&l=227

But generally it's a better idea to pass a time_fn into anything that uses time, and default to time.time if you're not in a unit test: https://cs.chromium.org/chromium/infra/packages/infra_libs/infra_libs/ts_mon/common/metric_store.py?sq=package:chromium&dr&l=62
Project Member

Comment 2 by sheriffbot@chromium.org, Aug 30 2016

Labels: Hotlist-Google

Comment 3 by ta...@google.com, Aug 31 2016

Status: WontFix (was: Untriaged)
I don't have the code anymore because I switch to time_fn.

But I mocked the time like this:

```
patcher = mock.patch('time.time', autospec=True)
self.time = patcher.start()
self.time.side_effect = [1, 2, 3]
```

That caused a lot of `???...UNKNOWN ERROR`. There were so many that pressing Ctrl+C didn't quit the process. I closed my terminal and just re-launched it again.

I guess it's not a problem now. I'll close the bug. Thanks!


Sign in to add a comment