Skip to content

Commit d7db913

Browse files
authored
fix concurrency_process test (#72)
* fix concurrency_process test: ConfigCat client cannot be pass to other process: reason="TypeError: can't pickle _thread.lock objects". To avoid this, we pass only the sdk_key and get the singleton instance in the process. * fix CI
1 parent 95e1f9f commit d7db913

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

configcatclienttests/test_concurrency.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,29 @@
1212
logging.basicConfig(level=logging.WARN)
1313

1414

15-
def _manual_force_refresh(client, repeat=10, delay=0.1):
16-
for i in range(repeat):
15+
def _manual_force_refresh(sdk_key, repeat=10, delay=0.1):
16+
client = configcatclient.get(sdk_key)
17+
for _ in range(repeat):
1718
client.force_refresh()
1819
sleep(delay)
1920

2021

2122
class ConcurrencyTests(unittest.TestCase):
22-
@pytest.mark.skipif(sys.platform == 'win32' or sys.platform == 'darwin', reason="TypeError: can't pickle _thread.lock objects")
23+
2324
def test_concurrency_process(self):
24-
client = configcatclient.get('PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A')
25+
sdk_key = "PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A"
26+
client = configcatclient.get(sdk_key)
2527
value = client.get_value('keySampleText', False, User('key'))
2628
print("'keySampleText' value from ConfigCat: " + str(value))
2729

28-
p1 = multiprocessing.Process(target=_manual_force_refresh, args=(client,))
29-
p2 = multiprocessing.Process(target=_manual_force_refresh, args=(client,))
30+
p1 = multiprocessing.Process(target=_manual_force_refresh, args=(sdk_key,))
31+
p2 = multiprocessing.Process(target=_manual_force_refresh, args=(sdk_key,))
3032
p1.start()
3133
p2.start()
3234
p1.join()
3335
p2.join()
3436

3537
client.close()
38+
39+
self.assertEqual(p1.exitcode, 0, "Process {0} exited with code {1}".format(p1.pid, p1.exitcode))
40+
self.assertEqual(p2.exitcode, 0, "Process {0} exited with code {1}".format(p2.pid, p2.exitcode))

0 commit comments

Comments
 (0)