You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.5 KiB

  1. chai = require "chai"
  2. chai.use(require "chai-increasing")
  3. {assert,expect} = chai
  4. Bluebird = require "bluebird"
  5. now = require "../"
  6. getUptime = -> process.uptime() * 1e3
  7. describe "now", ->
  8. it "reported time differs at most 1ms from a freshly reported uptime", ->
  9. assert.isAtMost Math.abs(now()-getUptime()), 1
  10. it "two subsequent calls return an increasing number", ->
  11. assert.isBelow now(), now()
  12. it "has less than 10 microseconds overhead", ->
  13. assert.isBelow Math.abs(now() - now()), 0.010
  14. it "can be called 1 million times in under 1 second (averaging under 1 microsecond per call)", ->
  15. @timeout 1000
  16. now() for [0...1e6]
  17. undefined
  18. it "for 10,000 numbers, number n is never bigger than number n-1", ->
  19. stamps = (now() for [1...10000])
  20. expect(stamps).to.be.increasing
  21. it "shows that at least 0.2 ms has passed after a timeout of 1 ms", ->
  22. earlier = now()
  23. Bluebird.resolve().delay(1).then -> assert.isAbove (now()-earlier), 0.2
  24. it "shows that at most 3 ms has passed after a timeout of 1 ms", ->
  25. earlier = now()
  26. Bluebird.resolve().delay(1).then -> assert.isBelow (now()-earlier), 3
  27. it "shows that at least 190ms ms has passed after a timeout of 200ms", ->
  28. earlier = now()
  29. Bluebird.resolve().delay(200).then -> assert.isAbove (now()-earlier), 190
  30. it "shows that at most 220 ms has passed after a timeout of 200ms", ->
  31. earlier = now()
  32. Bluebird.resolve().delay(200).then -> assert.isBelow (now()-earlier), 220