Cancel test passes
This commit is contained in:
parent
190b4268e1
commit
fd6e15bca8
@ -58,17 +58,17 @@ class TestXfer(utils.TempFileCleanupBaseTest):
|
||||
self.assertEqual(xfer.state, constants.States.STATE_COMPLETE)
|
||||
|
||||
def test_file_xfer_cancel(self):
|
||||
dst_file = self.get_tempfile()
|
||||
dst_file = "/dev/null"
|
||||
src_file = "/dev/zero"
|
||||
src_url = "file://%s" % src_file
|
||||
dst_url = "file://%s" % dst_file
|
||||
|
||||
xfer = xfer_iface.xfer_new(self.conf, src_url, dst_url,
|
||||
{}, {}, 0, None)
|
||||
db_obj = db.StaccatoDB(self.conf)
|
||||
xfer_iface.xfer_start(self.conf, xfer.id, self.sm)
|
||||
xfer_iface.xfer_cancel(self.conf, xfer.id, self.sm)
|
||||
|
||||
db_obj = db.StaccatoDB(self.conf)
|
||||
while not xfer_consts.is_state_done_running(xfer.state):
|
||||
time.sleep(0.1)
|
||||
xfer = db_obj.lookup_xfer_request_by_id(xfer.id)
|
||||
|
@ -1,7 +1,6 @@
|
||||
class Events:
|
||||
EVENT_NEW = "EVENT_NEW"
|
||||
EVENT_START = "EVENT_START"
|
||||
EVENT_STARTED = "EVENT_STARTED"
|
||||
EVENT_ERROR = "EVENT_ERROR"
|
||||
EVENT_COMPLETE = "EVENT_COMPLETE"
|
||||
EVENT_CANCEL = "EVENT_CANCEL"
|
||||
@ -10,7 +9,6 @@ class Events:
|
||||
|
||||
class States:
|
||||
STATE_NEW = "STATE_NEW"
|
||||
STATE_STARTING = "STATE_STARTING"
|
||||
STATE_RUNNING = "STATE_RUNNING"
|
||||
STATE_CANCELING = "STATE_CANCELING"
|
||||
STATE_CANCELED = "STATE_CANCELED"
|
||||
|
@ -37,20 +37,6 @@ class XferStateMachine(state_machine.StateMachine):
|
||||
This handler just allows for the DB change.
|
||||
"""
|
||||
|
||||
def state_starting_handler(
|
||||
self,
|
||||
current_state,
|
||||
event,
|
||||
new_state,
|
||||
conf,
|
||||
db,
|
||||
xfer_request,
|
||||
**kwvals):
|
||||
self.event_occurred(constants.Events.EVENT_STARTED,
|
||||
conf=conf,
|
||||
xfer_request=xfer_request,
|
||||
db=db)
|
||||
|
||||
def state_running_handler(
|
||||
self,
|
||||
current_state,
|
||||
@ -77,8 +63,6 @@ class XferStateMachine(state_machine.StateMachine):
|
||||
def map_states(self):
|
||||
self.set_state_func(constants.States.STATE_NEW,
|
||||
self.state_noop_handler)
|
||||
self.set_state_func(constants.States.STATE_STARTING,
|
||||
self.state_starting_handler)
|
||||
self.set_state_func(constants.States.STATE_RUNNING,
|
||||
self.state_running_handler)
|
||||
self.set_state_func(constants.States.STATE_CANCELING,
|
||||
@ -97,27 +81,18 @@ class XferStateMachine(state_machine.StateMachine):
|
||||
# setup the state machine
|
||||
self.set_mapping(constants.States.STATE_NEW,
|
||||
constants.Events.EVENT_START,
|
||||
constants.States.STATE_STARTING)
|
||||
constants.States.STATE_RUNNING)
|
||||
self.set_mapping(constants.States.STATE_NEW,
|
||||
constants.Events.EVENT_CANCEL,
|
||||
constants.States.STATE_CANCELED)
|
||||
self.set_mapping(constants.States.STATE_NEW,
|
||||
constants.Events.EVENT_START,
|
||||
constants.States.STATE_STARTING)
|
||||
|
||||
self.set_mapping(constants.States.STATE_CANCELED,
|
||||
constants.Events.EVENT_DELETE,
|
||||
constants.States.STATE_DELETED)
|
||||
|
||||
self.set_mapping(constants.States.STATE_STARTING,
|
||||
constants.Events.EVENT_STARTED,
|
||||
constants.States.STATE_RUNNING)
|
||||
self.set_mapping(constants.States.STATE_STARTING,
|
||||
constants.Events.EVENT_CANCEL,
|
||||
constants.States.STATE_CANCELING)
|
||||
self.set_mapping(constants.States.STATE_STARTING,
|
||||
constants.Events.EVENT_ERROR,
|
||||
constants.States.STATE_ERRORING)
|
||||
self.set_mapping(constants.States.STATE_CANCELING,
|
||||
constants.Events.EVENT_COMPLETE,
|
||||
constants.States.STATE_COMPLETE)
|
||||
|
||||
self.set_mapping(constants.States.STATE_RUNNING,
|
||||
constants.Events.EVENT_COMPLETE,
|
||||
@ -139,7 +114,7 @@ class XferStateMachine(state_machine.StateMachine):
|
||||
|
||||
self.set_mapping(constants.States.STATE_ERROR,
|
||||
constants.Events.EVENT_START,
|
||||
constants.States.STATE_STARTING)
|
||||
constants.States.STATE_RUNNING)
|
||||
|
||||
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
import time
|
||||
|
||||
import staccato.xfer.constants as constants
|
||||
import staccato.common.exceptions as exceptions
|
||||
@ -70,7 +71,7 @@ class XferReadMonitor(XferDBUpdater):
|
||||
|
||||
def is_done(self):
|
||||
self._check_db_ready()
|
||||
return constants.is_state_done_running(self.request.state)
|
||||
return self.request.state != constants.States.STATE_RUNNING
|
||||
|
||||
|
||||
class XferCheckpointer(XferDBUpdater):
|
||||
@ -109,6 +110,7 @@ class XferCheckpointer(XferDBUpdater):
|
||||
else:
|
||||
self.blocks[block_start] = block_end
|
||||
|
||||
time.sleep(0.1)
|
||||
self.blocks = _merge_one(self.blocks)
|
||||
|
||||
def _do_db_operation(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user