   beforeEach ->
     @cName = '_test'
     @docName2 = 'id1'
+    @testClient = createClient @db, (db) -> new TestDriver db
+    @testClient.driver.redis.select(15)
+    @testClient.driver.redis.flushdb()
 
   afterEach teardown
 
   it 'queues consecutive operations when they are not commited', calls 3, (done) -> @create =>
-    # TODO noansknv Assert all operations submitted.
-    client = createClient @db, (db) -> new TestDriver db
-
-    # TODO noansknv use consistently #15 in redis
-    client.driver.redis.flushdb()
-
-    # TODO noansknv: Refactor this monstrocity
-    @create2 @docName2
+    @createDoc @docName2
 
     # A submits 's1A' then 's2A', delay happens and it doesn't get sent to redis.
     # B submits 's1B' and is sent to redis immediately. 's2A' is sent to redis and
     # transformation is needed for 's1A' but per-useragent seq for A is wrong and
     # client is informed that 'Op already submitted'.
-    client.client.submit @cName, @docName, {v:1, op:['s1A'], seq:1, src: 'A', redisSubmitDelay: 50}, (err) ->
+    @testClient.client.submit @cName, @docName, {v:1, op:['s1A'], seq:1, src: 'A', redisSubmitDelay: 50}, (err) ->
       throw new Error err if err
       done()
 
-    client.client.submit @cName, @docName2, {v:1, op:['s2A'], seq:2, src: 'A', redisSubmitDelay: 10}, (err) ->
+    @testClient.client.submit @cName, @docName2, {v:1, op:['s2A'], seq:2, src: 'A', redisSubmitDelay: 10}, (err) ->
       throw new Error err if err
       done()
 
-    client.client.submit @cName, @docName, {v:1, op:['s1B'], seq:1, src: 'B'}, (err) =>
+    @testClient.client.submit @cName, @docName, {v:1, op:['s1B'], seq:1, src: 'B'}, (err) ->
       throw new Error err if err
       done()
 
-  it 'queues up operations per-client until the front of the queue is acknowledged', calls 2, (done) -> @create =>
-    client = createClient @db, (db) -> new TestDriver db
-    driver = client.driver
-
-    # TODO noansknv use consistently #15 in redis
-    driver.redis.flushdb()
+  it 'queues up operations per-client until the front of the queue is submitted to driver', calls 2, (done) -> @create =>
+    driver = @testClient.driver
 
     op1 =
       cName: @cName

# This used to be the whole set of tests - now some of the ancillary parts of
# livedb have been pulled out. These tests should probably be split out into
# multiple files.

livedb = require '../lib'
assert = require 'assert'
Q = require 'q'
inProcessDriver = require '../lib/inprocessdriver'
TestDriver = require './testdriver'

textType = require('ot-text').type
{createClient, setup, teardown, stripTs, calls} = require './util'

describe 'queue', ->
  beforeEach setup


    assert.equal driver.opList, undefined

    @testClient.client.submit @cName, @docName, {v:1, op: ['op1'], seq:1, src:'A', redisSubmitDelay:50}, (err) ->
      throw new Error err if err
      done()

    @testClient.client.submit @cName, @docName, {v:2, op: ['op2'], seq:2, src:'A', redisSubmitDelay:0}, (err) ->
      throw new Error err if err
      operationAssert driver.opList, [op1, op2]
      done()
