jonboulle / clockwork

a fake clock for golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Document that this does not affect Context.WithTimeout

sourcefrog opened this issue · comments

Hi, thanks for the nice package.

I was trying to fix some flaky tests by converting them to use this. However, the tests use Context.WithTimeout and it looks like the fake clock, even if injected into a context, is not respected by that code?

I can imagine how that might be impossible to fix without core library changes but it might be nice to document it to save people time?

All true, and I agree that it is unlikely we'd be able to get the core libraries to respect this. We can add documentation to that effect.

even if injected into a context

Just adding a personal note that I think injecting it into a context is not something I'd endorse. It was added to this package, but doesn't mean it is a great pattern. Since this package is all about testing, I'd advise adding the fake clocks directly to your structs as unexported fields.

Oh, good to know. Maybe that should be in the docs too, depending how much you want to editorialize?

I'll avoid it going forward, but it was just my attempt to get timeouts to work plus to deflake existing tests without major rewrites.

Added a warning on clockwork.AddToContext.