 	findQueue: (key, callback) ->
 		project_id = getProjectId(key)
 		migrationKey = @new_key_schema.projectHistoryMigrationKey({project_id})
-
+		migration_phase = @getMigrationPhase()  # allow setting migration phase while running for testing
 		@getMigrationStatus key, migrationKey, (err, migrationKeyExists, newQueueExists, oldQueueExists) =>
 			return callback(err) if err?
 			# In all cases, if the migration key exists we must always write to the
 			# new redis, unless we are rolling back.
-			if @migration_phase is "prepare"
+			if migration_phase is "prepare"
 			# in this phase we prepare for the switch, when some docupdaters will
 			# start setting the migration flag.  We monitor the migration key and
 			# write to the new redis if the key is present, but we do not set the

				multi.exec releaseLock

class MigrationClient
	constructor: (old_settings, new_settings) ->
		@rclient_old = redis.createClient(old_settings)
		@rclient_new = redis.createClient(new_settings)
		@new_key_schema = new_settings.key_schema
		@migration_phase = new_settings.migration_phase
		throw new Error("invalid migration phase") unless @migration_phase in ['prepare', 'switch', 'rollback']

	getMigrationStatus: (key, migrationKey, callback) ->
		async.series [

							return callback(err) if err?
							logger.debug {key: key}, "switching to new redis because old queue is empty"
							return callback(null, @rclient_new)
			else if migration_phase is "rollback"
				# If we need to roll back gracefully we do the opposite of the "switch"
				# phase. We use the new redis when the migration key is set and the
				# queue exists in the new redis, but if the queue in the new redis is
