title: Golang testing programs that involves time
body: <p>There is an object that relies on timing to function correctly. Unfortunately the timing duration itself is too long to realistically test it in real time and shortening the duration defeats the purpose of the testing due to the nature of the object.</p>
  
  <p>What is the best way to test such an object? Ideally, there would be some virtual clock that runs arbitrarily fast that can be used.</p>
  
  <pre><code>type Obj struct{}
  func (o Obj) TimeCriticalFunc(d time.Duration) bool {
      //do stuff
      //possibly calling multiple times time.Now() or other real time related functions
  }
  
  func TestTimeCriticalFunc(t *testing.T) {
      if !Obj{}.TimeCriticalFunc(10 * 24 * time.Hour) {
          t.Fail()
      }
  }
  </code></pre>