async def test_setting_cancels_and_resyncs(reader: ReaderHelper,
                                           ui_server: UiServer, config: Config,
                                           server, session, drive: DriveSource,
                                           coord: Coordinator):
    # Create a blocking sync task
    coord._sync_wait.set()
    sync = asyncio.create_task(coord.sync(), name="Sync from saving settings")
    await coord._sync_start.wait()
    assert not sync.cancelled()
    assert not sync.done()

    # Change some config
    update = {
        "config": {
            "days_between_snapshots": 20,
            "drive_ipv4": ""
        },
        "snapshot_folder": "unused"
    }
    assert await reader.postjson("saveconfig", json=update) == {
        'message': 'Settings saved'
    }

    # verify the previous sync is done and another one is running
    assert sync.done()
    assert coord.isSyncing()
async def test_working_through_upload(coord: Coordinator, global_info: GlobalInfo, dest):
    coord._sync_wait.clear()
    assert not coord.isWorkingThroughUpload()
    sync_task = asyncio.create_task(coord.sync())
    await coord._sync_start.wait()
    assert not coord.isWorkingThroughUpload()
    dest.working = True
    assert coord.isWorkingThroughUpload()
    coord._sync_wait.set()
    await asyncio.wait([sync_task])
    assert not coord.isWorkingThroughUpload()
async def test_cancel(coord: Coordinator, global_info: GlobalInfo):
    coord._sync_wait.clear()
    asyncio.create_task(coord.sync())
    await coord._sync_start.wait()
    await coord.cancel()
    assert isinstance(global_info._last_error, UserCancelledError)