import pytest

from pyrsistent import pmap
import random

import gc


def test_segfault_issue_52():
    threshold = gc.get_threshold()
    gc.set_threshold(1, 1, 1)  # fail fast

    v = [pmap()]

    def step():
        depth = random.randint(1, 10)
        path = random.sample(range(100000), depth)
        v[0] = v[0].transform(path, "foo")

    for i in range(1000):  # usually crashes after 10-20 steps
        while True:
            try:
                step()
                break
            except AttributeError:  # evolver on string
                continue

    gc.set_threshold(*threshold)

@@ -1,19 +1,4 @@
-import pytest%0A%0A
 from
@@ -93,16 +93,120 @@
 eshold =
+ None%0A    if hasattr(gc, 'get_threshold'):%0A        # PyPy is lacking these functions%0A        threshold =
  gc.get_
@@ -217,16 +217,20 @@
 shold()%0A
+    
     gc.s
@@ -659,16 +659,38 @@
 ntinue%0A%0A
+    if threshold:%0A    
     gc.s

Make regression test for #52 pass on PyPy