   return "--multipart-boundary--xxxxxxxxxxxxxxxxxxxxxxxx--"
 mockRequire("../../../libs/request", MultipartData)
 
+RequestMock = {
+  always : (promise, func) -> promise.then(func, func)
+  sendArraybufferReceiveArraybuffer : sinon.stub()
+  foo : 0
+}
+mockRequire("../../../libs/request", RequestMock)
+
+PullQueue = require("../../../oxalis/model/binary/pullqueue")
+
 describe "PullQueue", ->
-
-  RequestMock = null
 
   dataSetName = "dataset"
   layer = {

sinon = require("sinon")
runAsync = require("../../helpers/run-async")
{Bucket} = require("../../../oxalis/model/binary/bucket")

MultipartData = require("../../../libs/multipart_data")
# FileReader is not available in node context


  describe "Successful pulling", ->

    buckets = null
    bucketData1 = (i % 256 for i in [0...(32 * 32 * 32)])
    bucketData2 = ((2 * i) % 256 for i in [0...(32 * 32 * 32)])

    beforeEach ->

      buckets = [new Bucket(8, [0, 0, 0, 0], null), new Bucket(8, [1, 1, 1, 1], null)]

      for bucket in buckets
        pullQueue.add({bucket: bucket.zoomedAddress, priority : 0})
        cube.getBucketByZoomedAddress.withArgs(bucket.zoomedAddress).returns(bucket)

      responseBuffer = bucketData1.concat(bucketData2)
      RequestMock.sendArraybufferReceiveArraybuffer.reset()
      RequestMock.sendArraybufferReceiveArraybuffer.returns(Promise.resolve(responseBuffer))


