<commit_before>#!/usr/bin/env python3
# Copyright (c) 2017-2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test multiwallet.

Verify that a bitcoind node can load multiple wallet files
"""
import os
import shutil
import time
from decimal import Decimal
from threading import Thread

from test_framework.authproxy import JSONRPCException
from test_framework.test_framework import BitcoinTestFramework
from test_framework.test_node import ErrorMatch
from test_framework.util import (
    assert_equal,
    assert_raises_rpc_error,
    get_rpc_proxy,
)

got_loading_error = False


def test_load_unload(node, name):
    global got_loading_error
    for _ in range(10):
        if got_loading_error:
            return
        try:
            node.loadwallet(name)
            node.unloadwallet(name)
        except JSONRPCException as e:
            if e.error['code'] == - \
                    4 and 'Wallet already being loading' in e.error['message']:
                got_loading_error = True
                return


class MultiWalletTest(BitcoinTestFramework):
    def set_test_params(self):<commit_msg>test: Fix intermittent wallet_multiwallet issue with got_loading_error<commit_after>#!/usr/bin/env python3
# Copyright (c) 2017-2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test multiwallet.

Verify that a bitcoind node can load multiple wallet files
"""
import os
import shutil
import time
from decimal import Decimal
from threading import Thread

from test_framework.authproxy import JSONRPCException
from test_framework.test_framework import BitcoinTestFramework
from test_framework.test_node import ErrorMatch
from test_framework.util import (
    assert_equal,
    assert_raises_rpc_error,
    get_rpc_proxy,
)

got_loading_error = False


def test_load_unload(node, name, timeout=60.):
    global got_loading_error
    t0 = time.time()
    while time.time() - t0 < timeout and not got_loading_error:
        try:
            node.loadwallet(name)
            node.unloadwallet(name)
        except JSONRPCException as e:
            if e.error['code'] == - \
                    4 and 'Wallet already being loading' in e.error['message']:
                got_loading_error = True
                return
        # Add a small sleep to avoid CPU exhaustion in the unlikely case
        # the race never happens.
        time.sleep(0.001)


class MultiWalletTest(BitcoinTestFramework):
    def set_test_params(self):
{'fraction_non_alphanumeric': 0.0675625233296006, 'fraction_numerical': 0.011198208286674132, 'mean_word_length': 3.2338072669826223, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4876459', 'n_tokens_mistral': 761, 'n_tokens_neox': 737, 'n_words': 232}