def test_multiprocessing_safety(mongo_host, library_name):
    # Create/initialize library at the parent process, then spawn children, and start them aligned in time
    total_processes = 64
    total_writes_per_child = 100

    register_get_auth_hook(my_auth_hook)

    global MY_ARCTIC
    MY_ARCTIC = Arctic(mongo_host=mongo_host)

    MY_ARCTIC.initialize_library(library_name, VERSION_STORE)
    assert isinstance(MY_ARCTIC.get_library(library_name), VersionStore)

    processes = [
        Process(target=f, args=(library_name, total_writes_per_child, True))
        for _ in range(total_processes)
    ]

    for p in processes:
        p.start()

    for p in processes:
        p.join()

    for p in processes:
        assert p.exitcode == 0

    assert isinstance(MY_ARCTIC.get_library(library_name), VersionStore)
Esempio n. 2
0
def test_get_auth_hook():
    auth_resolver = Mock()
    register_get_auth_hook(auth_resolver)
    get_auth(sentinel.host, sentinel.app_name, sentinel.database_name)
    assert auth_resolver.call_args_list == [
        call(sentinel.host, sentinel.app_name, sentinel.database_name)
    ]
def test_multiprocessing_safety(mongo_host, library_name):
    # Create/initialize library at the parent process, then spawn children, and start them aligned in time
    total_processes = 64
    total_writes_per_child = 100

    register_get_auth_hook(my_auth_hook)

    global MY_ARCTIC
    MY_ARCTIC = Arctic(mongo_host=mongo_host)

    MY_ARCTIC.initialize_library(library_name, VERSION_STORE)
    assert isinstance(MY_ARCTIC.get_library(library_name), VersionStore)

    processes = [Process(target=f, args=(library_name, total_writes_per_child, True)) for _ in range(total_processes)]

    for p in processes:
        p.start()

    for p in processes:
        p.join()

    for p in processes:
        assert p.exitcode == 0

    assert isinstance(MY_ARCTIC.get_library(library_name), VersionStore)
Esempio n. 4
0
def setPWD(user=None, passwd=None):
    if user is not None:
        auth = lambda: None
        auth.user = user
        auth.password = passwd
        register_get_auth_hook(lambda *x, **y: auth)
    else:
        register_get_auth_hook(lambda *x, **y: None)
Esempio n. 5
0
import os
from arctic import Arctic
from arctic.auth import Credential
from arctic.hooks import register_get_auth_hook

ARCTIC_HOST = os.environ.get("BELLA_TICKS_HOST", "localhost")
ARCTIC_USER = os.environ.get("BELLA_TICKS_USER")
ARCTIC_PASSWD = os.environ.get("BELLA_TICKS_PASSWD")


def arctic_auth_hook(mongo_host, app, database):
    return Credential(
        database="arctic",
        user=ARCTIC_USER,
        password=ARCTIC_PASSWD,
    )


if ARCTIC_USER and ARCTIC_PASSWD:
    # 注册认证钩子
    register_get_auth_hook(arctic_auth_hook)

arctic = Arctic(ARCTIC_HOST)
Esempio n. 6
0
def test_get_auth_hook():
    auth_resolver = Mock()
    register_get_auth_hook(auth_resolver)
    get_auth(sentinel.host, sentinel.app_name, sentinel.database_name)
    assert auth_resolver.call_args_list == [call(sentinel.host, sentinel.app_name, sentinel.database_name)]