将persist和后端分离,方便替换为其他数据库
This commit is contained in:
@@ -7,6 +7,7 @@ import pytest
|
||||
|
||||
from sync_state_machine.common.collection import DataCollection
|
||||
from sync_state_machine.common.persistence import PersistenceBackend
|
||||
from sync_state_machine.common.sqlite_backend import SQLitePersistenceBackend
|
||||
from sync_state_machine.common.types import BindingStatus, SyncAction, SyncStatus
|
||||
from sync_state_machine.engine.dispatcher import StateMachineRuntime
|
||||
from sync_state_machine.engine.model import StateMachineConfig
|
||||
@@ -21,7 +22,7 @@ from tests.mocks.mock_datasource import (
|
||||
@pytest.fixture
|
||||
def datasource_bundle():
|
||||
db = Path(tempfile.mkdtemp(prefix="sync_state_machine_mock_ds_")) / "state.db"
|
||||
persistence = PersistenceBackend(str(db))
|
||||
persistence = SQLitePersistenceBackend(str(db))
|
||||
cfg_path = Path(__file__).resolve().parents[2] / "sync_state_machine" / "config" / "node_state_machine.yaml"
|
||||
runtime = StateMachineRuntime(StateMachineConfig.load(cfg_path))
|
||||
collection = DataCollection("mock", persistence=None, auto_persist=False)
|
||||
@@ -49,7 +50,7 @@ async def test_create_success_to_s11(datasource_bundle):
|
||||
node = _new_node("n1", SyncAction.CREATE)
|
||||
await collection.add(node)
|
||||
|
||||
datasource.register_handler(ScriptedMockHandler(HandlerScript(create="success")))
|
||||
datasource.add_handler(ScriptedMockHandler(HandlerScript(create="success")))
|
||||
datasource.set_collection(collection)
|
||||
await datasource.sync_all(data_type="mock")
|
||||
|
||||
@@ -62,7 +63,7 @@ async def test_create_skipped_is_rejected(datasource_bundle):
|
||||
node = _new_node("n2", SyncAction.CREATE)
|
||||
await collection.add(node)
|
||||
|
||||
datasource.register_handler(ScriptedMockHandler(HandlerScript(create="skipped")))
|
||||
datasource.add_handler(ScriptedMockHandler(HandlerScript(create="skipped")))
|
||||
datasource.set_collection(collection)
|
||||
await datasource.sync_all(data_type="mock")
|
||||
|
||||
@@ -76,7 +77,7 @@ async def test_update_skip_downgrade_to_s14(datasource_bundle):
|
||||
node = _new_node("n3", SyncAction.UPDATE)
|
||||
await collection.add(node)
|
||||
|
||||
datasource.register_handler(
|
||||
datasource.add_handler(
|
||||
ScriptedMockHandler(HandlerScript(update="skipped"))
|
||||
)
|
||||
datasource.set_collection(collection)
|
||||
@@ -94,7 +95,7 @@ async def test_update_success_writes_back_origin_data(datasource_bundle):
|
||||
node.set_data({"id": "n3b", "name": "after"})
|
||||
await collection.add(node)
|
||||
|
||||
datasource.register_handler(ScriptedMockHandler(HandlerScript(update="success")))
|
||||
datasource.add_handler(ScriptedMockHandler(HandlerScript(update="success")))
|
||||
datasource.set_collection(collection)
|
||||
await datasource.sync_all(data_type="mock")
|
||||
|
||||
@@ -109,7 +110,7 @@ async def test_in_progress_poll_success_to_s11(datasource_bundle):
|
||||
node = _new_node("n4", SyncAction.CREATE)
|
||||
await collection.add(node)
|
||||
|
||||
datasource.register_handler(
|
||||
datasource.add_handler(
|
||||
ScriptedMockHandler(HandlerScript(create="in_progress", poll_sequence=["success"]))
|
||||
)
|
||||
datasource.set_collection(collection)
|
||||
@@ -124,7 +125,7 @@ async def test_in_progress_poll_timeout_to_s12(datasource_bundle):
|
||||
node = _new_node("n5", SyncAction.CREATE)
|
||||
await collection.add(node)
|
||||
|
||||
datasource.register_handler(
|
||||
datasource.add_handler(
|
||||
ScriptedMockHandler(HandlerScript(create="in_progress", poll_sequence=["in_progress", "in_progress"]))
|
||||
)
|
||||
datasource.set_collection(collection)
|
||||
|
||||
Reference in New Issue
Block a user