Skip to content

Commit

Permalink
TEST: Add a non-regression test to ensure sorting takes a reasonably …
Browse files Browse the repository at this point in the history
…short time
  • Loading branch information
effigies committed Jun 22, 2021
1 parent 1491be9 commit b92c296
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import enum
import typing
from functools import wraps
import time

import pytest

Expand Down Expand Up @@ -60,6 +61,8 @@
_TEST_GLOBAL_VARIABLE = "default_value"
_TEST_GLOBAL_VARIABLE2 = "another_value"

exec("def _TEST_BIG_GLOBAL_SPACE():\n return %s" % ", ".join([f"a{i}" for i in range(1000)]))


class RaiserOnPickle(object):

Expand Down Expand Up @@ -2339,6 +2342,16 @@ def func_with_globals():
add_env={"PYTHONHASHSEED": str(i)}))
assert len(vals) == 1

def test_efficient_sorted_globals(self):
# Non regression test to demonstrate that large numbers of globals
# do not cause slowdown
gvars = set(f"a{i}" for i in range(1000))
assert cloudpickle.cloudpickle._extract_code_globals(
_TEST_BIG_GLOBAL_SPACE.__code__) == gvars
tic = time.time()
subprocess_pickle_string(_TEST_BIG_GLOBAL_SPACE, protocol=self.protocol)
assert time.time() - tic < 0.5


class Protocol2CloudPickleTest(CloudPickleTest):

Expand Down

0 comments on commit b92c296

Please sign in to comment.