curds: Switch to using the asyncio module for testing threading
I'm planning to use the asyncio code for running background threads, so let's switch to it for now to get a feel for how it works. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
2a98aac6de
commit
9b64c590cc
|
@ -1,6 +1,7 @@
|
||||||
# Copyright 2019 (c) Anna Schumaker
|
# Copyright 2019 (c) Anna Schumaker
|
||||||
|
import asyncio
|
||||||
|
import concurrent.futures
|
||||||
import hashlib
|
import hashlib
|
||||||
from multiprocessing.pool import ThreadPool
|
|
||||||
import unittest
|
import unittest
|
||||||
import album
|
import album
|
||||||
|
|
||||||
|
@ -58,8 +59,8 @@ class TestAlbumClass(unittest.TestCase):
|
||||||
|
|
||||||
def test_parallel_lookup(self):
|
def test_parallel_lookup(self):
|
||||||
album.album_map.clear()
|
album.album_map.clear()
|
||||||
with ThreadPool(processes=5) as pool:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as pool:
|
||||||
res = pool.map(album.lookup, [ album_info ] * 20)
|
res = list(pool.map(album.lookup, [ album_info ] * 20))
|
||||||
self.assertIsNotNone(res[0])
|
self.assertIsNotNone(res[0])
|
||||||
self.assertEqual(res.count(res[0]), 20)
|
self.assertEqual(res.count(res[0]), 20)
|
||||||
self.assertEqual(len(album.album_map), 1)
|
self.assertEqual(len(album.album_map), 1)
|
||||||
|
|
Loading…
Reference in New Issue