travis-web/assets/scripts/spec/unit/log_chunks_spec.coffee
Robert Jackson 9011f9d85d
Pass test suite.
* Add `travis.source_endpoint` meta (fixes many tests with hard
  expectations on `http://github.com` being in URL paths).
* Wrap `Ember.run.once` in a `Ember.run` (prevents test auto-run
  assertion).
* Fix expect counts for a couple tests.
2014-11-04 21:22:58 -05:00

74 lines
2.2 KiB
CoffeeScript

module "Travis.LogChunks"
test "it doesn't trigger downloading missing parts if they come in timely fashion", ->
expect(2)
stop()
callback = -> ok false, 'callback should not be called'
chunks = Travis.LogChunks.create(timeout: 15, missingPartsCallback: callback, content: [])
setTimeout (-> chunks.pushObject(number: 1, final: false)), 10
setTimeout (-> chunks.pushObject(number: 2, final: false)), 20
setTimeout ->
ok true
chunks.pushObject(number: 3, final: true)
start()
equal(chunks.get('finalized'), true, 'log should be finalized')
, 30
test "it triggers downloading missing parts if there is a missing part, even though final part arrived", ->
expect(2)
stop()
callback = (missingNumbers) ->
deepEqual(missingNumbers, [2, 3], 'callback should be called with missing numbers')
chunks = Travis.LogChunks.create(timeout: 15, missingPartsCallback: callback, content: [])
chunks.pushObject(number: 1, final: false)
setTimeout ->
chunks.pushObject(number: 4, final: true)
ok(!chunks.get('finalized'), "log shouldn't be finalized")
, 10
setTimeout ->
Ember.run -> chunks.destroy() # destroy object to not fire more callbacks
start()
, 40
test "it triggers downloading next parts if there is no final part", ->
expect(4)
stop()
callback = (missingNumbers, after) ->
deepEqual(missingNumbers, [2], 'callback should be called with missing numbers')
equal(after, 3, 'callback should be called with "after" argument')
chunks = Travis.LogChunks.create(timeout: 15, missingPartsCallback: callback, content: [])
chunks.pushObject(number: 1, final: false)
chunks.pushObject(number: 3, final: false)
setTimeout ->
Ember.run -> chunks.destroy() # destroy object to not fire more callbacks
start()
, 35
test "it triggers downloading all available parts if there is no parts yet", ->
expect(2)
stop()
callback = (missingNumbers, after) ->
ok(!missingNumbers, 'there should be no missing parts')
ok(!after, 'after should not be specified')
chunks = Travis.LogChunks.create(timeout: 15, missingPartsCallback: callback, content: [])
setTimeout ->
Ember.run -> chunks.destroy() # destroy object to not fire more callbacks
start()
, 25