Skip to content

Commit

Permalink
Compare counters
Browse files Browse the repository at this point in the history
  • Loading branch information
vovaf709 committed Jan 20, 2023
1 parent 0522452 commit 633c0f4
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions tests/batch_iter/test_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from collections import Counter
from itertools import repeat

import pytest
Expand Down Expand Up @@ -38,25 +39,32 @@ def test_parallel():
assert abs(faster - delta / 2) < sleep


# TODO: uncomment as soon as #68 is solved
# def test_loky():
# size = 100
# for i, item in enumerate(wrap_pipeline(range(size), Loky(lambda x: x ** 2, n_workers=2))):
# assert item == i ** 2
# assert i == size - 1
# # at this point the first worker is killed
# # start a new one
# for i, item in enumerate(wrap_pipeline(range(size), Loky(lambda x: x ** 2, n_workers=2))):
# assert item == i ** 2
# assert i == size - 1

# # several workers
# for i, item in enumerate(wrap_pipeline(
# range(size),
# Loky(lambda x: x ** 2, n_workers=2),
# Loky(lambda x: x ** 2, n_workers=2))):
# assert item == i ** 4
# assert i == size - 1
# TODO: check order of output itmes as soon as #68 is solved
def test_loky():
size = 100

source_items = list(range(size))
items = []

for i, item in enumerate(wrap_pipeline(source_items, Loky(lambda x: x ** 2, n_workers=2))):
items.append(item)
assert Counter(items) == Counter(map(lambda x: x ** 2, source_items))
# at this point the first worker is killed
# start a new one
items = []
for i, item in enumerate(wrap_pipeline(range(size), Loky(lambda x: x ** 2, n_workers=2))):
items.append(item)
assert Counter(items) == Counter(map(lambda x: x ** 2, source_items))

# several workers
items = []
for i, item in enumerate(wrap_pipeline(
range(size),
Loky(lambda x: x ** 2, n_workers=2),
Loky(lambda x: x ** 2, n_workers=2))):
items.append(item)
assert Counter(items) == Counter(map(lambda x: x ** 4, source_items))
assert i == size - 1


def test_premature_stop():
Expand Down

0 comments on commit 633c0f4

Please sign in to comment.