本文整理汇总了Python中keywords.MobileRestClient.MobileRestClient.get_changes方法的典型用法代码示例。如果您正苦于以下问题:Python MobileRestClient.get_changes方法的具体用法?Python MobileRestClient.get_changes怎么用?Python MobileRestClient.get_changes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keywords.MobileRestClient.MobileRestClient
的用法示例。
在下文中一共展示了MobileRestClient.get_changes方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_backfill_channels_oneshot_changes
# 需要导入模块: from keywords.MobileRestClient import MobileRestClient [as 别名]
# 或者: from keywords.MobileRestClient.MobileRestClient import get_changes [as 别名]
def test_backfill_channels_oneshot_changes(params_from_base_test_setup, sg_conf_name, grant_type):
cluster_config = params_from_base_test_setup["cluster_config"]
topology = params_from_base_test_setup["cluster_topology"]
mode = params_from_base_test_setup["mode"]
sg_url = topology["sync_gateways"][0]["public"]
sg_admin_url = topology["sync_gateways"][0]["admin"]
sg_db = "db"
log_info("grant_type: {}".format(grant_type))
sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode)
cluster = Cluster(cluster_config)
cluster.reset(sg_conf)
client = MobileRestClient()
admin_user_info = userinfo.UserInfo("admin", "pass", channels=["A"], roles=[])
user_b_user_info = userinfo.UserInfo("USER_B", "pass", channels=["B"], roles=[])
# Create users / sessions
client.create_user(url=sg_admin_url, db=sg_db,
name=admin_user_info.name, password=admin_user_info.password, channels=admin_user_info.channels)
client.create_user(url=sg_admin_url, db=sg_db,
name=user_b_user_info.name, password=user_b_user_info.password, channels=user_b_user_info.channels)
admin_session = client.create_session(url=sg_admin_url, db=sg_db, name=admin_user_info.name, password=admin_user_info.password)
user_b_session = client.create_session(url=sg_admin_url, db=sg_db, name=user_b_user_info.name, password=user_b_user_info.password)
# Create 50 "A" channel docs
a_docs = client.add_docs(url=sg_url, db=sg_db, number=50, id_prefix=None, auth=admin_session, channels=["A"])
assert len(a_docs) == 50
b_docs = client.add_docs(url=sg_url, db=sg_db, number=1, id_prefix="b_doc", auth=user_b_session, channels=["B"])
assert len(b_docs) == 1
user_doc = {"id": "_user/USER_B", "rev": None}
b_docs.append(user_doc)
# Loop until user_b sees b_doc_0 doc and _user/USER_B doc
client.verify_docs_in_changes(url=sg_url, db=sg_db, expected_docs=b_docs, auth=user_b_session, strict=True)
# Get last_seq for user_b
user_b_changes = client.get_changes(url=sg_url, db=sg_db, since=0, auth=user_b_session, feed="normal")
# Grant access to channel "A"
if grant_type == "CHANNEL-REST":
log_info("Granting user access to channel A via Admin REST user update")
# Grant via update to user in Admin API
client.update_user(url=sg_admin_url, db=sg_db,
name=user_b_user_info.name, channels=["A", "B"])
elif grant_type == "CHANNEL-SYNC":
log_info("Granting user access to channel A sync function access()")
# Grant via access() in sync_function, then id 'channel_access' will trigger an access(doc.users, doc.channels)
access_doc = document.create_doc("channel_access", channels=["A"])
access_doc["users"] = ["USER_B"]
client.add_doc(url=sg_url, db=sg_db, doc=access_doc, auth=admin_session)
elif grant_type == "ROLE-REST":
log_info("Granting user access to channel A via Admin REST role grant")
# Create role with channel A
client.create_role(url=sg_admin_url, db=sg_db, name="channel-A-role", channels=["A"])
client.update_user(url=sg_admin_url, db=sg_db, name="USER_B", roles=["channel-A-role"])
elif grant_type == "ROLE-SYNC":
log_info("Granting user access to channel A via sync function role() grant")
# Create role with channel A
client.create_role(url=sg_admin_url, db=sg_db, name="channel-A-role", channels=["A"])
# Grant via role() in sync_function, then id 'role_access' will trigger an role(doc.users, doc.roles)
role_access_doc = document.create_doc("role_access")
role_access_doc["users"] = ["USER_B"]
role_access_doc["roles"] = ["role:channel-A-role"]
client.add_doc(sg_url, db=sg_db, doc=role_access_doc, auth=admin_session)
else:
pytest.fail("Unsupported grant_type!!!!")
user_b_changes_after_grant = client.get_changes(url=sg_url, db=sg_db,
since=user_b_changes["last_seq"], auth=user_b_session, feed="normal")
# User B shoud have recieved 51 docs (a_docs + 1 _user/USER_B doc) if a REST grant or 50 changes if the grant
# is via the sync function
changes_results = user_b_changes_after_grant["results"]
assert 50 <= len(changes_results) <= 51
# Create a dictionary of id rev pair of all the docs that are not "_user/" docs from changes
ids_and_revs_from_user_changes = {
change["id"]: change["changes"][0]["rev"]
for change in changes_results if not change["id"].startswith("_user/")
}
assert len(ids_and_revs_from_user_changes) == 50
# Create a list of id rev pair of all of the channel A docs
ids_and_revs_from_a_docs = {doc["id"]: doc["rev"] for doc in a_docs}
#.........这里部分代码省略.........
示例2: test_backfill_channels_looping_longpoll_changes
# 需要导入模块: from keywords.MobileRestClient import MobileRestClient [as 别名]
# 或者: from keywords.MobileRestClient.MobileRestClient import get_changes [as 别名]
def test_backfill_channels_looping_longpoll_changes(params_from_base_test_setup, sg_conf_name, grant_type):
cluster_config = params_from_base_test_setup["cluster_config"]
topology = params_from_base_test_setup["cluster_topology"]
mode = params_from_base_test_setup["mode"]
sg_url = topology["sync_gateways"][0]["public"]
sg_admin_url = topology["sync_gateways"][0]["admin"]
sg_db = "db"
log_info("grant_type: {}".format(grant_type))
sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode)
cluster = Cluster(cluster_config)
cluster.reset(sg_conf)
client = MobileRestClient()
admin_user_info = userinfo.UserInfo("admin", "pass", channels=["A"], roles=[])
user_b_user_info = userinfo.UserInfo("USER_B", "pass", channels=["B"], roles=[])
# Create users / sessions
client.create_user(url=sg_admin_url, db=sg_db,
name=admin_user_info.name, password=admin_user_info.password, channels=admin_user_info.channels)
client.create_user(url=sg_admin_url, db=sg_db,
name=user_b_user_info.name, password=user_b_user_info.password, channels=user_b_user_info.channels)
admin_session = client.create_session(url=sg_admin_url, db=sg_db, name=admin_user_info.name, password=admin_user_info.password)
user_b_session = client.create_session(url=sg_admin_url, db=sg_db, name=user_b_user_info.name, password=user_b_user_info.password)
# Create 50 "A" channel docs
a_docs = client.add_docs(url=sg_url, db=sg_db, number=50, id_prefix=None, auth=admin_session, channels=["A"])
assert len(a_docs) == 50
b_docs = client.add_docs(url=sg_url, db=sg_db, number=1, id_prefix="b_doc", auth=user_b_session, channels=["B"])
assert len(b_docs) == 1
user_doc = {"id": "_user/USER_B", "rev": None}
b_docs.append(user_doc)
# Loop until user_b sees b_doc_0 doc and _user/USER_B doc
client.verify_docs_in_changes(url=sg_url, db=sg_db, expected_docs=b_docs, auth=user_b_session, strict=True)
# Create a dictionary keyed on doc id for all of channel A docs
ids_and_revs_from_a_docs = {doc["id"]: doc["rev"] for doc in a_docs}
assert len(ids_and_revs_from_a_docs.keys()) == 50
# Get last_seq for user_b
user_b_changes = client.get_changes(url=sg_url, db=sg_db, since=0, auth=user_b_session, feed="normal")
with concurrent.futures.ProcessPoolExecutor() as ex:
# Start long poll changes feed.
changes_task = ex.submit(client.get_changes,
url=sg_url, db=sg_db, since=user_b_changes["last_seq"], auth=user_b_session, timeout=10, limit=20)
# Grant access to channel "A"
if grant_type == "CHANNEL-REST":
log_info("Granting user access to channel A via Admin REST user update")
# Grant via update to user in Admin API
client.update_user(url=sg_admin_url, db=sg_db,
name=user_b_user_info.name, channels=["A", "B"])
elif grant_type == "CHANNEL-SYNC":
log_info("Granting user access to channel A sync function access()")
# Grant via access() in sync_function, then id 'channel_access' will trigger an access(doc.users, doc.channels)
access_doc = document.create_doc("channel_access", channels=["A"])
access_doc["users"] = ["USER_B"]
client.add_doc(url=sg_url, db=sg_db, doc=access_doc, auth=admin_session)
elif grant_type == "ROLE-REST":
log_info("Granting user access to channel A via Admin REST role grant")
# Create role with channel A
client.create_role(url=sg_admin_url, db=sg_db, name="channel-A-role", channels=["A"])
client.update_user(url=sg_admin_url, db=sg_db, name="USER_B", roles=["channel-A-role"])
elif grant_type == "ROLE-SYNC":
log_info("Granting user access to channel A via sync function role() grant")
# Create role with channel A
client.create_role(url=sg_admin_url, db=sg_db, name="channel-A-role", channels=["A"])
# Grant via role() in sync_function, then id 'role_access' will trigger an role(doc.users, doc.roles)
role_access_doc = document.create_doc("role_access")
role_access_doc["users"] = ["USER_B"]
role_access_doc["roles"] = ["role:channel-A-role"]
client.add_doc(sg_url, db=sg_db, doc=role_access_doc, auth=admin_session)
else:
pytest.fail("Unsupported grant_type!!!!")
# Block on return of longpoll changes, feed should wake up and return 20 results
changes = changes_task.result()
assert len(changes["results"]) == 20
num_requests = 1
# Cross the results off from the 'a_docs' dictionary
for doc in changes["results"]:
#.........这里部分代码省略.........
示例3: test_remove_add_channels_to_doc
# 需要导入模块: from keywords.MobileRestClient import MobileRestClient [as 别名]
# 或者: from keywords.MobileRestClient.MobileRestClient import get_changes [as 别名]
def test_remove_add_channels_to_doc(params_from_base_test_setup, sg_conf_name):
cluster_config = params_from_base_test_setup["cluster_config"]
topology = params_from_base_test_setup["cluster_topology"]
mode = params_from_base_test_setup["mode"]
sg_url = topology["sync_gateways"][0]["public"]
sg_admin_url = topology["sync_gateways"][0]["admin"]
sg_db = "db"
sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode)
cluster = Cluster(cluster_config)
cluster.reset(sg_conf)
client = MobileRestClient()
admin_user_info = userinfo.UserInfo("admin", "pass", channels=["A", "B"], roles=[])
a_user_info = userinfo.UserInfo("a_user", "pass", channels=["A"], roles=[])
admin_user_auth = client.create_user(
url=sg_admin_url,
db=sg_db,
name=admin_user_info.name,
password=admin_user_info.password,
channels=admin_user_info.channels,
)
a_user_auth = client.create_user(
url=sg_admin_url, db=sg_db, name=a_user_info.name, password=a_user_info.password, channels=a_user_info.channels
)
a_docs = client.add_docs(
url=sg_url, db=sg_db, number=50, id_prefix="a_doc", auth=admin_user_auth, channels=admin_user_info.channels
)
# Build dictionay of a_docs
a_docs_id_rev = {doc["id"]: doc["rev"] for doc in a_docs}
assert len(a_docs_id_rev) == 50
# Wait for all docs to show up in changes
client.verify_doc_id_in_changes(sg_url, sg_db, expected_doc_id="_user/a_user", auth=a_user_auth)
client.verify_docs_in_changes(sg_url, sg_db, expected_docs=a_docs, auth=a_user_auth)
# Get changes for 'a_user'
a_user_changes = client.get_changes(url=sg_url, db=sg_db, since=0, auth=a_user_auth, feed="normal")
# 'a_user' should get 50 'a_doc_*' doc and 1 '_user/a_user' doc
assert len(a_user_changes["results"]) == 51
###########################
# Remove Channels from doc
###########################
# Copy a_docs_id_rev to dictionary to scratch off values
remove_docs_scratch_off = a_docs_id_rev.copy()
assert len(remove_docs_scratch_off) == 50
# Use admin user to update the docs to remove 'A' from the channels property on the doc and add 'B'
client.update_docs(url=sg_url, db=sg_db, docs=a_docs, number_updates=1, auth=admin_user_auth, channels=["B"])
# Longpoll loop requires due to the delay that changes take to permeate to the client
changes_timeout = 10
start = time.time()
last_seq = a_user_changes["last_seq"]
while True:
# If take longer than 10 seconds, fail the test
if time.time() - start > changes_timeout:
raise keywords.exceptions.TimeoutException("Could not find all expected docs in changs feed")
# We found everything, exit loop!
if remove_docs_scratch_off == {}:
log_info("All expected docs found to be removed")
break
# Get changes for 'a_user' from last_seq
a_user_changes = client.get_changes(url=sg_url, db=sg_db, since=last_seq, auth=a_user_auth, timeout=10)
assert len(a_user_changes["results"]) > 0
# Loop over changes found and perform the following
# 1. Check that the docs is flagged with 'removed'
# 2. Cross off the doc fromt the the 'remove_docs_scratch_off'
for change in a_user_changes["results"]:
assert change["removed"] == ["A"]
assert change["changes"][0]["rev"].startswith("2-")
# This will blow up if any change is not found in that dictionary
del remove_docs_scratch_off[change["id"]]
# Update last_seq
last_seq = a_user_changes["last_seq"]
# Issue changes request from 'last_seq' and verify that the changes are up to date and returns no results
a_user_changes = client.get_changes(url=sg_url, db=sg_db, since=last_seq, auth=a_user_auth, feed="normal")
assert len(a_user_changes["results"]) == 0
#########################
# Add Channels to doc
#########################
#.........这里部分代码省略.........
示例4: test_backfill_channels_oneshot_limit_changes
# 需要导入模块: from keywords.MobileRestClient import MobileRestClient [as 别名]
# 或者: from keywords.MobileRestClient.MobileRestClient import get_changes [as 别名]
def test_backfill_channels_oneshot_limit_changes(params_from_base_test_setup, sg_conf_name, grant_type):
cluster_config = params_from_base_test_setup["cluster_config"]
topology = params_from_base_test_setup["cluster_topology"]
mode = params_from_base_test_setup["mode"]
sg_url = topology["sync_gateways"][0]["public"]
sg_admin_url = topology["sync_gateways"][0]["admin"]
sg_db = "db"
log_info("grant_type: {}".format(grant_type))
sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode)
cluster = Cluster(cluster_config)
cluster.reset(sg_conf)
client = MobileRestClient()
admin_user_info = userinfo.UserInfo("admin", "pass", channels=["A"], roles=[])
user_b_user_info = userinfo.UserInfo("USER_B", "pass", channels=["B"], roles=[])
# Create users / sessions
client.create_user(url=sg_admin_url, db=sg_db,
name=admin_user_info.name, password=admin_user_info.password, channels=admin_user_info.channels)
client.create_user(url=sg_admin_url, db=sg_db,
name=user_b_user_info.name, password=user_b_user_info.password, channels=user_b_user_info.channels)
admin_session = client.create_session(url=sg_admin_url, db=sg_db, name=admin_user_info.name, password=admin_user_info.password)
user_b_session = client.create_session(url=sg_admin_url, db=sg_db, name=user_b_user_info.name, password=user_b_user_info.password)
# Create 50 "A" channel docs
a_docs = client.add_docs(url=sg_url, db=sg_db, number=50, id_prefix=None, auth=admin_session, channels=["A"])
assert len(a_docs) == 50
b_docs = client.add_docs(url=sg_url, db=sg_db, number=1, id_prefix="b_doc", auth=user_b_session, channels=["B"])
assert len(b_docs) == 1
user_doc = {"id": "_user/USER_B", "rev": None}
b_docs.append(user_doc)
# Loop until user_b sees b_doc_0 doc and _user/USER_B doc
client.verify_docs_in_changes(url=sg_url, db=sg_db, expected_docs=b_docs, auth=user_b_session, strict=True)
# Get last_seq for user_b
user_b_changes = client.get_changes(url=sg_url, db=sg_db, since=0, auth=user_b_session, feed="normal")
# Grant access to channel "A"
if grant_type == "CHANNEL-REST":
log_info("Granting user access to channel A via Admin REST user update")
# Grant via update to user in Admin API
client.update_user(url=sg_admin_url, db=sg_db,
name=user_b_user_info.name, channels=["A", "B"])
elif grant_type == "CHANNEL-SYNC":
log_info("Granting user access to channel A sync function access()")
# Grant via access() in sync_function, then id 'channel_access' will trigger an access(doc.users, doc.channels)
access_doc = document.create_doc("channel_access", channels=["A"])
access_doc["users"] = ["USER_B"]
client.add_doc(url=sg_url, db=sg_db, doc=access_doc, auth=admin_session)
elif grant_type == "ROLE-REST":
log_info("Granting user access to channel A via Admin REST role grant")
# Create role with channel A
client.create_role(url=sg_admin_url, db=sg_db, name="channel-A-role", channels=["A"])
client.update_user(url=sg_admin_url, db=sg_db, name="USER_B", roles=["channel-A-role"])
elif grant_type == "ROLE-SYNC":
log_info("Granting user access to channel A via sync function role() grant")
# Create role with channel A
client.create_role(url=sg_admin_url, db=sg_db, name="channel-A-role", channels=["A"])
# Grant via role() in sync_function, then id 'role_access' will trigger an role(doc.users, doc.roles)
role_access_doc = document.create_doc("role_access")
role_access_doc["users"] = ["USER_B"]
role_access_doc["roles"] = ["role:channel-A-role"]
client.add_doc(sg_url, db=sg_db, doc=role_access_doc, auth=admin_session)
else:
pytest.fail("Unsupported grant_type!!!!")
# Create a dictionary keyed on doc id for all of channel A docs
ids_and_revs_from_a_docs = {doc["id"]: doc["rev"] for doc in a_docs}
assert len(ids_and_revs_from_a_docs.keys()) == 50
log_info("Doing 3, 1 shot changes with limit and last seq!")
# Issue 3 oneshot changes with a limit of 20
#################
# Changes Req #1
#################
user_b_changes_after_grant_one = client.get_changes(url=sg_url, db=sg_db,
since=user_b_changes["last_seq"], auth=user_b_session, feed="normal", limit=20)
# User B shoud have recieved 20 docs due to limit
assert len(user_b_changes_after_grant_one["results"]) == 20
for doc in user_b_changes_after_grant_one["results"]:
# cross off keys found from 'a_docs' dictionary
#.........这里部分代码省略.........
示例5: test_longpoll_awaken_roles
# 需要导入模块: from keywords.MobileRestClient import MobileRestClient [as 别名]
# 或者: from keywords.MobileRestClient.MobileRestClient import get_changes [as 别名]
def test_longpoll_awaken_roles(params_from_base_test_setup, sg_conf_name):
cluster_conf = params_from_base_test_setup["cluster_config"]
cluster_topology = params_from_base_test_setup["cluster_topology"]
mode = params_from_base_test_setup["mode"]
sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode)
sg_admin_url = cluster_topology["sync_gateways"][0]["admin"]
sg_url = cluster_topology["sync_gateways"][0]["public"]
log_info("sg_conf: {}".format(sg_conf))
log_info("sg_admin_url: {}".format(sg_admin_url))
log_info("sg_url: {}".format(sg_url))
cluster = Cluster(config=cluster_conf)
cluster.reset(sg_config_path=sg_conf)
admin_role = "admin_role"
admin_channel = "admin_channel"
admin_user_info = userinfo.UserInfo(name="admin", password="pass", channels=[], roles=[admin_role])
adam_user_info = userinfo.UserInfo(name="adam", password="Adampass1", channels=[], roles=[])
traun_user_info = userinfo.UserInfo(name="traun", password="Traunpass1", channels=[], roles=[])
andy_user_info = userinfo.UserInfo(name="andy", password="Andypass1", channels=[], roles=[])
sg_db = "db"
client = MobileRestClient()
# Create a role on sync_gateway
client.create_role(url=sg_admin_url, db=sg_db, name=admin_role, channels=[admin_channel])
# Create users with no channels or roles
admin_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=admin_user_info.name, password=admin_user_info.password, roles=[admin_role])
adam_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=adam_user_info.name, password=adam_user_info.password)
traun_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=traun_user_info.name, password=traun_user_info.password)
andy_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=andy_user_info.name, password=andy_user_info.password)
################################
# change feed wakes for role add
################################
# Get starting sequence of docs, use the last seq to progress past any _user docs.
adam_changes = client.get_changes(url=sg_url, db=sg_db, since=0, feed="normal", auth=adam_auth)
traun_changes = client.get_changes(url=sg_url, db=sg_db, since=0, feed="normal", auth=traun_auth)
andy_changes = client.get_changes(url=sg_url, db=sg_db, since=0, feed="normal", auth=andy_auth)
# Add doc with channel associated with the admin role
admin_doc = client.add_docs(url=sg_url, db=sg_db, number=1, id_prefix="admin_doc", auth=admin_auth, channels=[admin_channel])
client.verify_docs_in_changes(url=sg_url, db=sg_db, expected_docs=admin_doc, auth=admin_auth)
with concurrent.futures.ProcessPoolExecutor() as ex:
# Start changes feed for 3 users from latest last_seq
adam_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=adam_changes["last_seq"], timeout=10, auth=adam_auth)
traun_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=traun_changes["last_seq"], timeout=10, auth=traun_auth)
andy_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=andy_changes["last_seq"], timeout=10, auth=andy_auth)
# Wait for changes feed to notice there are no changes and enter wait. 2 seconds should be more than enough
time.sleep(2)
# Make sure the changes future is still running and has not exited due to any new changes, the feed should be caught up
# and waiting
assert not adam_changes_task.done()
assert not traun_changes_task.done()
assert not andy_changes_task.done()
adam_auth = client.update_user(url=sg_admin_url, db=sg_db,
name=adam_user_info.name, password=adam_user_info.password, roles=[admin_role])
traun_auth = client.update_user(url=sg_admin_url, db=sg_db,
name=traun_user_info.name, password=traun_user_info.password, roles=[admin_role])
andy_auth = client.update_user(url=sg_admin_url, db=sg_db,
name=andy_user_info.name, password=andy_user_info.password, roles=[admin_role])
adam_changes = adam_changes_task.result()
assert 1 <= len(adam_changes["results"]) <= 2
assert adam_changes["results"][0]["id"] == "admin_doc_0" or adam_changes["results"][0]["id"] == "_user/adam"
traun_changes = traun_changes_task.result()
assert 1 <= len(traun_changes["results"]) <= 2
assert traun_changes["results"][0]["id"] == "admin_doc_0" or traun_changes["results"][0]["id"] == "_user/traun"
andy_changes = andy_changes_task.result()
assert 1 <= len(andy_changes["results"]) <= 2
assert andy_changes["results"][0]["id"] == "admin_doc_0" or andy_changes["results"][0]["id"] == "_user/andy"
# Check that the user docs all show up in changes feed
client.verify_doc_id_in_changes(url=sg_url, db=sg_db, expected_doc_id="_user/adam", auth=adam_auth)
client.verify_doc_id_in_changes(url=sg_url, db=sg_db, expected_doc_id="_user/traun", auth=traun_auth)
client.verify_doc_id_in_changes(url=sg_url, db=sg_db, expected_doc_id="_user/andy", auth=andy_auth)
# Check that the admin doc made it to all the changes feeds
client.verify_docs_in_changes(url=sg_url, db=sg_db, expected_docs=admin_doc, auth=adam_auth)
#.........这里部分代码省略.........
示例6: test_longpoll_awaken_via_sync_role
# 需要导入模块: from keywords.MobileRestClient import MobileRestClient [as 别名]
# 或者: from keywords.MobileRestClient.MobileRestClient import get_changes [as 别名]
def test_longpoll_awaken_via_sync_role(params_from_base_test_setup, sg_conf_name):
"""
Test that longpoll changes feed wakes up on role() in sync_function
The contrived sync_function below is used:
function(doc, oldDoc){
if(doc._id == "role_doc_0") {
console.log("granting_access!");
role(["adam", "traun", "andy"], "role:techno");
}
channel(doc, doc.channels);
}
"""
cluster_conf = params_from_base_test_setup["cluster_config"]
cluster_topology = params_from_base_test_setup["cluster_topology"]
mode = params_from_base_test_setup["mode"]
sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode)
sg_admin_url = cluster_topology["sync_gateways"][0]["admin"]
sg_url = cluster_topology["sync_gateways"][0]["public"]
log_info("sg_conf: {}".format(sg_conf))
log_info("sg_admin_url: {}".format(sg_admin_url))
log_info("sg_url: {}".format(sg_url))
sg_db = "db"
techno_role = "techno"
techno_channel = "aphex"
cluster = Cluster(config=cluster_conf)
cluster.reset(sg_config_path=sg_conf)
client = MobileRestClient()
client.create_role(url=sg_admin_url, db=sg_db, name=techno_role, channels=[techno_channel])
admin_user_info = userinfo.UserInfo(name="admin", password="pass", channels=[], roles=[techno_role])
adam_user_info = userinfo.UserInfo(name="adam", password="Adampass1", channels=[], roles=[])
traun_user_info = userinfo.UserInfo(name="traun", password="Traunpass1", channels=[], roles=[])
andy_user_info = userinfo.UserInfo(name="andy", password="Andypass1", channels=[], roles=[])
admin_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=admin_user_info.name, password=admin_user_info.password, roles=adam_user_info.roles)
adam_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=adam_user_info.name, password=adam_user_info.password)
traun_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=traun_user_info.name, password=traun_user_info.password)
andy_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=andy_user_info.name, password=andy_user_info.password)
client.add_docs(url=sg_url, db=sg_db, number=1, id_prefix="techno_doc", channels=[techno_channel], auth=admin_auth)
# Get starting sequence of docs, use the last seq to progress past any _user docs.
adam_changes = client.get_changes(url=sg_url, db=sg_db, since=0, feed="normal", auth=adam_auth)
traun_changes = client.get_changes(url=sg_url, db=sg_db, since=0, feed="normal", auth=traun_auth)
andy_changes = client.get_changes(url=sg_url, db=sg_db, since=0, feed="normal", auth=andy_auth)
with concurrent.futures.ProcessPoolExecutor() as ex:
# Start changes feed for 3 users from latest last_seq
adam_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=adam_changes["last_seq"], timeout=10, auth=adam_auth)
traun_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=traun_changes["last_seq"], timeout=10, auth=traun_auth)
andy_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=andy_changes["last_seq"], timeout=10, auth=andy_auth)
# Wait for changes feed to notice there are no changes and enter wait. 2 seconds should be more than enough
time.sleep(2)
# Make sure the changes future is still running and has not exited due to any new changes, the feed should be caught up
# and waiting
assert not adam_changes_task.done()
assert not traun_changes_task.done()
assert not andy_changes_task.done()
# Grant adam, traun and andy access to the "NATGEO" channel
client.add_docs(url=sg_url, db=sg_db, number=1, id_prefix="role_doc", channels=[], auth=admin_auth)
# Changes feed should wake up with the natgeo_0 doc
adam_changes = adam_changes_task.result()
assert len(adam_changes["results"]) == 1
assert adam_changes["results"][0]["id"] == "techno_doc_0"
assert adam_changes["results"][0]["changes"][0]["rev"].startswith("1-")
traun_changes = traun_changes_task.result()
assert len(traun_changes["results"]) == 1
assert traun_changes["results"][0]["id"] == "techno_doc_0"
assert traun_changes["results"][0]["changes"][0]["rev"].startswith("1-")
andy_changes = andy_changes_task.result()
assert len(andy_changes["results"]) == 1
assert andy_changes["results"][0]["id"] == "techno_doc_0"
assert andy_changes["results"][0]["changes"][0]["rev"].startswith("1-")
# Assert that the changes are caught up and should recieve no new changes from last_seq
# Test for https://github.com/couchbase/sync_gateway/issues/2186
adam_changes = client.get_changes(url=sg_url, db=sg_db, since=adam_changes["last_seq"], auth=adam_auth, timeout=1)
assert len(adam_changes["results"]) == 0
traun_changes = client.get_changes(url=sg_url, db=sg_db, since=traun_changes["last_seq"], auth=traun_auth, timeout=1)
#.........这里部分代码省略.........
示例7: test_longpoll_awaken_channels
# 需要导入模块: from keywords.MobileRestClient import MobileRestClient [as 别名]
# 或者: from keywords.MobileRestClient.MobileRestClient import get_changes [as 别名]
def test_longpoll_awaken_channels(params_from_base_test_setup, sg_conf_name):
cluster_conf = params_from_base_test_setup["cluster_config"]
cluster_topology = params_from_base_test_setup["cluster_topology"]
mode = params_from_base_test_setup["mode"]
sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode)
sg_admin_url = cluster_topology["sync_gateways"][0]["admin"]
sg_url = cluster_topology["sync_gateways"][0]["public"]
log_info("sg_conf: {}".format(sg_conf))
log_info("sg_admin_url: {}".format(sg_admin_url))
log_info("sg_url: {}".format(sg_url))
cluster = Cluster(config=cluster_conf)
cluster.reset(sg_config_path=sg_conf)
adam_user_info = userinfo.UserInfo(name="adam", password="Adampass1", channels=["NBC", "ABC"], roles=[])
traun_user_info = userinfo.UserInfo(name="traun", password="Traunpass1", channels=[], roles=[])
andy_user_info = userinfo.UserInfo(name="andy", password="Andypass1", channels=[], roles=[])
sg_db = "db"
doc_id = "adam_doc_0"
client = MobileRestClient()
adam_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=adam_user_info.name, password=adam_user_info.password, channels=adam_user_info.channels)
traun_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=traun_user_info.name, password=traun_user_info.password, channels=traun_user_info.channels)
andy_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=andy_user_info.name, password=andy_user_info.password, channels=andy_user_info.channels)
############################################################
# changes feed wakes with Channel Access via Admin API
############################################################
# Get starting sequence of docs, use the last seq to progress past any _user docs.
adam_changes = client.get_changes(url=sg_url, db=sg_db, since=0, feed="normal", auth=adam_auth)
traun_changes = client.get_changes(url=sg_url, db=sg_db, since=0, feed="normal", auth=traun_auth)
andy_changes = client.get_changes(url=sg_url, db=sg_db, since=0, feed="normal", auth=andy_auth)
with concurrent.futures.ProcessPoolExecutor() as ex:
# Start changes feed for 3 users
adam_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=adam_changes["last_seq"], timeout=10, auth=adam_auth)
traun_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=traun_changes["last_seq"], timeout=10, auth=traun_auth)
andy_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=andy_changes["last_seq"], timeout=10, auth=andy_auth)
# Wait for changes feed to notice there are no changes and enter wait. 2 seconds should be more than enough
time.sleep(2)
# Make sure the changes future is still running and has not exited due to any new changes, the feed should be caught up
# and waiting
assert not adam_changes_task.done()
assert not traun_changes_task.done()
assert not andy_changes_task.done()
# Add add a doc for adam with "NBC" and "ABC" channels
# Add one doc, this should wake up the changes feed
adam_add_docs_task = ex.submit(client.add_docs, url=sg_url, db=sg_db,
number=1, id_prefix="adam_doc",
auth=adam_auth, channels=adam_user_info.channels)
# Wait for docs adds to complete
adam_docs = adam_add_docs_task.result()
assert len(adam_docs) == 1
# Assert that the changes feed woke up and that the doc change was propagated
adam_changes = adam_changes_task.result()
assert len(adam_changes["results"]) == 1
assert adam_changes["results"][0]["id"] == doc_id
# Verify that the changes feed is still listening for Traun and Andy
assert not traun_changes_task.done()
assert not andy_changes_task.done()
# Update the traun and andy to have one of adam's channels
update_traun_user_task = ex.submit(client.update_user, url=sg_admin_url, db=sg_db,
name=traun_user_info.name, password=traun_user_info.password, channels=["NBC"])
traun_auth = update_traun_user_task.result()
update_andy_user_task = ex.submit(client.update_user, url=sg_admin_url, db=sg_db,
name=andy_user_info.name, password=andy_user_info.password, channels=["ABC"])
andy_auth = update_andy_user_task.result()
# Make sure changes feed wakes up and contains at least one change, 2 may be possible if the _user doc is included
# Make sure the first change is 'adam_doc'
traun_changes = traun_changes_task.result()
assert 1 <= len(traun_changes["results"]) <= 2
assert traun_changes["results"][0]["id"] == "adam_doc_0" or traun_changes["results"][0]["id"] == "_user/traun"
andy_changes = andy_changes_task.result()
assert 1 <= len(andy_changes["results"]) <= 2
assert andy_changes["results"][0]["id"] == "adam_doc_0" or andy_changes["results"][0]["id"] == "_user/andy"
# Block until user docs are seen
client.verify_doc_id_in_changes(url=sg_url, db=sg_db, expected_doc_id="_user/adam", auth=adam_auth)
client.verify_doc_id_in_changes(url=sg_url, db=sg_db, expected_doc_id="_user/traun", auth=traun_auth)
#.........这里部分代码省略.........
示例8: test_longpoll_awaken_doc_add_update
# 需要导入模块: from keywords.MobileRestClient import MobileRestClient [as 别名]
# 或者: from keywords.MobileRestClient.MobileRestClient import get_changes [as 别名]
def test_longpoll_awaken_doc_add_update(params_from_base_test_setup, sg_conf_name):
cluster_conf = params_from_base_test_setup["cluster_config"]
mode = params_from_base_test_setup["mode"]
cluster_topology = params_from_base_test_setup["cluster_topology"]
sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode)
sg_admin_url = cluster_topology["sync_gateways"][0]["admin"]
sg_url = cluster_topology["sync_gateways"][0]["public"]
log_info("sg_conf: {}".format(sg_conf))
log_info("sg_admin_url: {}".format(sg_admin_url))
log_info("sg_url: {}".format(sg_url))
cluster = Cluster(config=cluster_conf)
cluster.reset(sg_config_path=sg_conf)
adam_user_info = userinfo.UserInfo(name="adam", password="Adampass1", channels=["NBC"], roles=[])
traun_user_info = userinfo.UserInfo(name="traun", password="Traunpass1", channels=["CBS"], roles=[])
andy_user_info = userinfo.UserInfo(name="andy", password="Andypass1", channels=["MTV"], roles=[])
sg_db = "db"
client = MobileRestClient()
adam_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=adam_user_info.name, password=adam_user_info.password, channels=adam_user_info.channels)
traun_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=traun_user_info.name, password=traun_user_info.password, channels=traun_user_info.channels)
andy_auth = client.create_user(url=sg_admin_url, db=sg_db,
name=andy_user_info.name, password=andy_user_info.password, channels=andy_user_info.channels)
# Get starting sequence of docs, use the last seq to progress past any user docs
adam_changes = client.get_changes(url=sg_url, db=sg_db, since=0, feed="normal", auth=adam_auth)
traun_changes = client.get_changes(url=sg_url, db=sg_db, since=0, feed="normal", auth=traun_auth)
andy_changes = client.get_changes(url=sg_url, db=sg_db, since=0, feed="normal", auth=andy_auth)
with concurrent.futures.ProcessPoolExecutor() as ex:
adam_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=adam_changes["last_seq"], timeout=30, auth=adam_auth)
traun_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=traun_changes["last_seq"], timeout=30, auth=traun_auth)
andy_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=andy_changes["last_seq"], timeout=30, auth=andy_auth)
# Wait for changes feed to notice there are no changes and enter wait. 2 seconds should be more than enough
time.sleep(2)
# Make sure the changes future is still running and has not exited due to any new changes, the feed should be caught up
# and waiting
assert not adam_changes_task.done()
assert not traun_changes_task.done()
assert not andy_changes_task.done()
# Add 3 docs with adam auth, one with adam channels, one with traun channels, one with andy auth
# Tests the changes feed wakes up for user created docs and non user created docs
adam_add_doc_task_1 = ex.submit(client.add_docs, url=sg_url, db=sg_db,
number=1, id_prefix="adam_doc",
auth=adam_auth, channels=adam_user_info.channels)
adam_add_doc_task_2 = ex.submit(client.add_docs, url=sg_url, db=sg_db,
number=1, id_prefix="traun_doc",
auth=adam_auth, channels=traun_user_info.channels)
adam_add_doc_task_3 = ex.submit(client.add_docs, url=sg_url, db=sg_db,
number=1, id_prefix="andy_doc",
auth=adam_auth, channels=andy_user_info.channels)
# Wait for docs adds to complete
adam_doc_1 = adam_add_doc_task_1.result()
assert len(adam_doc_1) == 1
adam_doc_2 = adam_add_doc_task_2.result()
assert len(adam_doc_2) == 1
adam_doc_3 = adam_add_doc_task_3.result()
assert len(adam_doc_3) == 1
# Assert that the changes feed woke up and that the doc change was propagated
adam_changes = adam_changes_task.result()
assert len(adam_changes["results"]) == 1
assert adam_changes["results"][0]["id"] == "adam_doc_0"
traun_changes = traun_changes_task.result()
assert len(traun_changes["results"]) == 1
assert traun_changes["results"][0]["id"] == "traun_doc_0"
andy_changes = andy_changes_task.result()
assert len(andy_changes["results"]) == 1
assert andy_changes["results"][0]["id"] == "andy_doc_0"
# Start another longpoll changes request
adam_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=adam_changes["last_seq"], auth=adam_auth)
traun_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=traun_changes["last_seq"], auth=traun_auth)
andy_changes_task = ex.submit(client.get_changes, url=sg_url, db=sg_db, since=andy_changes["last_seq"], auth=andy_auth)
# Wait for changes feed to notice there are no changes and enter wait. 2 seconds should be more than enough
time.sleep(2)
# Make sure the changes future is still running and has not exited due to any new changes, the feed should be caught up
# and waiting
assert not adam_changes_task.done()
#.........这里部分代码省略.........
示例9: test_non_winning_revisions
# 需要导入模块: from keywords.MobileRestClient import MobileRestClient [as 别名]
# 或者: from keywords.MobileRestClient.MobileRestClient import get_changes [as 别名]
def test_non_winning_revisions(params_from_base_test_setup, sg_conf_name):
""" Add non-winning revisions to the revision tree and ensure
that the changes feed returns the correct revisions
Steps:
- Create a doc
- Add 5 revs
- changes, assert rev starts with "6-" from 0, store "last_seq_1"
- Create a conflict off first revision ("2-foo") (POST docs, new_edits == false)
- changes, assert rev starts with "6-" from "last_seq_1", store "last_seq_2"
- changes, assert rev starts with "6-" from 0
- Add a "3-foo" rev with rev "2-foo" as parent
- changes, assert rev starts with "6-" from "last_seq_2", store "last_seq_3"
- changes, assert rev starts with "6-" from 0
- add tombstone rev as child of "6-" i.e. issue delete on ("6-")
- changes, assert rev starts with "3-foo" from "last_seq_3"
- changes, assert rev starts with "3-foo" from 0
"""
cluster_config = params_from_base_test_setup["cluster_config"]
topology = params_from_base_test_setup["cluster_topology"]
mode = params_from_base_test_setup["mode"]
sg_url = topology["sync_gateways"][0]["public"]
sg_admin_url = topology["sync_gateways"][0]["admin"]
sg_db = "db"
sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode)
c = cluster.Cluster(cluster_config)
c.reset(sg_conf)
client = MobileRestClient()
seth_user_info = userinfo.UserInfo(
name="seth",
password="pass",
channels=["NATGEO"],
roles=[]
)
seth_auth = client.create_user(
url=sg_admin_url,
db=sg_db,
name=seth_user_info.name,
password=seth_user_info.password,
channels=seth_user_info.channels
)
test_doc_body = document.create_doc(doc_id="test_doc", channels=seth_user_info.channels)
rev_gen_1_doc = client.add_doc(url=sg_url, db=sg_db, doc=test_doc_body, auth=seth_auth)
rev_gen_6_doc = client.update_doc(url=sg_url, db=sg_db, doc_id=rev_gen_1_doc["id"], number_updates=5, auth=seth_auth)
assert rev_gen_6_doc["rev"].startswith("6-")
# Get changes until rev generation 6 document shows up
start = time.time()
last_seq = 0
while True:
if time.time() - start > keywords.constants.CLIENT_REQUEST_TIMEOUT:
raise keywords.exceptions.TimeoutError("Wait for Replication Status Idle: TIMEOUT")
changes_1 = client.get_changes(url=sg_url, db=sg_db, since=last_seq, auth=seth_auth, skip_user_docs=True)
last_seq = changes_1["last_seq"]
# break when expected rev shows up in changes feed
if changes_1["results"] and changes_1["results"][0]["changes"][0]["rev"].startswith("6-"):
break
assert len(changes_1["results"]) == 1
assert changes_1["results"][0]["id"] == "test_doc"
assert changes_1["results"][0]["changes"][0]["rev"].startswith("6-")
# Create a conflict off of rev one
rev_gen_2_doc_conflict = client.add_conflict(
url=sg_url,
db=sg_db,
doc_id=rev_gen_1_doc["id"],
parent_revisions=rev_gen_1_doc["rev"],
new_revision="2-foo",
auth=seth_auth
)
assert rev_gen_2_doc_conflict["id"] == "test_doc"
assert rev_gen_2_doc_conflict["rev"] == "2-foo"
# Issue changes since changes_1 last_seq above
changes_2 = client.get_changes(url=sg_url, db=sg_db, since=changes_1["last_seq"], auth=seth_auth)
assert len(changes_2["results"]) == 1
assert changes_2["results"][0]["id"] == "test_doc"
assert changes_2["results"][0]["changes"][0]["rev"].startswith("6-")
# Issue changes since 0, strip user doc and make sure the doc is still the '6-' rev
changes_from_0_one = client.get_changes(url=sg_url, db=sg_db, since=0, auth=seth_auth, skip_user_docs=True)
assert len(changes_from_0_one["results"]) == 1
assert changes_from_0_one["results"][0]["id"] == "test_doc"
assert changes_from_0_one["results"][0]["changes"][0]["rev"].startswith("6-")
# Create a 3-foo rev with 2-foo as the parent
rev_gen_3_doc_conflict = client.add_conflict(
url=sg_url,
#.........这里部分代码省略.........
示例10: test_winning_conflict_branch_revisions
# 需要导入模块: from keywords.MobileRestClient import MobileRestClient [as 别名]
# 或者: from keywords.MobileRestClient.MobileRestClient import get_changes [as 别名]
def test_winning_conflict_branch_revisions(params_from_base_test_setup, sg_conf_name):
""" Add winning conflict revisions to the revision tree and ensure
that the changes feed returns the correct revisions
Steps:
- Create a doc ('test_doc')
- Add 5 revs to 'test_doc'
- POST _changes, assert rev starts with "6-" from 0, store "last_seq_1"
- Create a conflict off first revision ("2-foo") (POST docs, new_edits == false)
- Append 5 revisions to the conflicting branch
(3-foo with 2-foo as parent, 4-foo with 3-foo as parent ... 7-foo with 6-foo as parent)
- GET 'test_doc' and verify that the rev is '7-foo'
- POST _changes, assert returns 7-foo
"""
cluster_config = params_from_base_test_setup["cluster_config"]
topology = params_from_base_test_setup["cluster_topology"]
mode = params_from_base_test_setup["mode"]
sg_url = topology["sync_gateways"][0]["public"]
sg_admin_url = topology["sync_gateways"][0]["admin"]
sg_db = "db"
sg_conf = sync_gateway_config_path_for_mode(sg_conf_name, mode)
c = cluster.Cluster(cluster_config)
c.reset(sg_conf)
client = MobileRestClient()
seth_user_info = userinfo.UserInfo(
name="seth",
password="pass",
channels=["NATGEO"],
roles=[]
)
seth_auth = client.create_user(
url=sg_admin_url,
db=sg_db,
name=seth_user_info.name,
password=seth_user_info.password,
channels=seth_user_info.channels
)
test_doc_body = document.create_doc(doc_id="test_doc", channels=seth_user_info.channels)
rev_gen_1_doc = client.add_doc(url=sg_url, db=sg_db, doc=test_doc_body, auth=seth_auth)
rev_gen_6_doc = client.update_doc(url=sg_url, db=sg_db, doc_id=rev_gen_1_doc["id"], number_updates=5, auth=seth_auth)
assert rev_gen_6_doc["rev"].startswith("6-")
# Wait until doc shows up in changes feed
last_seq = 0
start = time.time()
while True:
if time.time() - start > keywords.constants.CLIENT_REQUEST_TIMEOUT:
raise keywords.exceptions.TimeoutError("Wait for Replication Status Idle: TIMEOUT")
changes_1 = client.get_changes(url=sg_url, db=sg_db, since=last_seq, auth=seth_auth, skip_user_docs=True)
last_seq = changes_1["last_seq"]
if len(changes_1["results"]) > 0 and changes_1["results"][0]["changes"][0]["rev"].startswith("6-"):
break
assert len(changes_1["results"]) == 1
assert changes_1["results"][0]["id"] == "test_doc"
assert changes_1["results"][0]["changes"][0]["rev"].startswith("6-")
# Create a conflict off of rev one
rev_gen_1_doc_conflict = client.add_conflict(
url=sg_url,
db=sg_db,
doc_id=rev_gen_1_doc["id"],
parent_revisions=rev_gen_1_doc["rev"],
new_revision="2-foo",
auth=seth_auth
)
# Update the conflicting branch 5x
rev_gen = 3
for _ in range(5):
rev_gen_1_doc_conflict = client.add_conflict(
url=sg_url,
db=sg_db,
doc_id=rev_gen_1_doc["id"],
parent_revisions=rev_gen_1_doc_conflict["rev"],
new_revision="{}-foo".format(rev_gen),
auth=seth_auth
)
rev_gen += 1
# Wait until doc shows up in changes feed from last_seq from where last changes loop from above left off
start = time.time()
while True:
if time.time() - start > keywords.constants.CLIENT_REQUEST_TIMEOUT:
raise keywords.exceptions.TimeoutError("Wait for Replication Status Idle: TIMEOUT")
changes_2 = client.get_changes(url=sg_url, db=sg_db, since=last_seq, auth=seth_auth)
last_seq = changes_2["last_seq"]
#.........这里部分代码省略.........
示例11: test_server_goes_down_rebuild_channels
# 需要导入模块: from keywords.MobileRestClient import MobileRestClient [as 别名]
# 或者: from keywords.MobileRestClient.MobileRestClient import get_changes [as 别名]
def test_server_goes_down_rebuild_channels(params_from_base_test_setup):
"""
1. Start with a two node couchbase server cluster
2. Starting adding docs
3. Kill one of the server nodes and signal completion
4. Stop adding docs
5. Verify that that the expected docs are present and in the changes feed.
6. Start server again and add to cluster
"""
cluster_config = params_from_base_test_setup["cluster_config"]
mode = params_from_base_test_setup["mode"]
cluster_helper = ClusterKeywords()
sg_conf_name = "sync_gateway_default_functional_tests"
sg_conf_path = sync_gateway_config_path_for_mode(sg_conf_name, mode)
cluster_helper.reset_cluster(cluster_config=cluster_config,
sync_gateway_config=sg_conf_path)
topology = cluster_helper.get_cluster_topology(cluster_config)
admin_sg = topology["sync_gateways"][0]["admin"]
sg_url = topology["sync_gateways"][0]["public"]
coucbase_servers = topology["couchbase_servers"]
cbs_one_url = coucbase_servers[0]
cbs_two_url = coucbase_servers[1]
log_info("Running: 'test_server_goes_down_sanity'")
log_info("cluster_config: {}".format(cluster_config))
log_info("admin_sg: {}".format(admin_sg))
log_info("sg_url: {}".format(sg_url))
log_info("cbs_one_url: {}".format(cbs_one_url))
log_info("cbs_two_url: {}".format(cbs_two_url))
sg_db = "db"
num_docs = 100
admin_user_info = userinfo.UserInfo(
name="admin",
password="password",
channels=["ABC"],
roles=[]
)
seth_user_info = userinfo.UserInfo(
name="seth",
password="password",
channels=["ABC"],
roles=[]
)
client = MobileRestClient()
main_server = CouchbaseServer(cbs_one_url)
flakey_server = CouchbaseServer(cbs_two_url)
admin_auth = client.create_user(
admin_sg,
sg_db,
admin_user_info.name,
admin_user_info.password,
channels=admin_user_info.channels
)
client.create_user(
admin_sg,
sg_db,
seth_user_info.name,
seth_user_info.password,
channels=seth_user_info.channels
)
seth_session = client.create_session(admin_sg, sg_db, seth_user_info.name)
# allow any user docs to make it to changes
initial_changes = client.get_changes(url=sg_url, db=sg_db, since=0, auth=seth_session)
# push docs from admin
docs = client.add_docs(
url=sg_url,
db=sg_db,
number=num_docs,
id_prefix=None,
channels=admin_user_info.channels,
auth=admin_auth
)
assert len(docs) == num_docs
client.verify_docs_in_changes(url=sg_url, db=sg_db, expected_docs=docs, auth=seth_session)
changes_before_failover = client.get_changes(url=sg_url, db=sg_db, since=initial_changes["last_seq"], auth=seth_session)
assert len(changes_before_failover["results"]) == num_docs
# Stop server via 'service stop'
flakey_server.stop()
start = time.time()
while True:
# Fail tests if all docs do not succeed before timeout
#.........这里部分代码省略.........