summaryrefslogtreecommitdiff
path: root/tests/extmod/btree_gc.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/extmod/btree_gc.py')
-rw-r--r--tests/extmod/btree_gc.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/extmod/btree_gc.py b/tests/extmod/btree_gc.py
new file mode 100644
index 000000000..153f4e7d7
--- /dev/null
+++ b/tests/extmod/btree_gc.py
@@ -0,0 +1,23 @@
+# Test btree interaction with the garbage collector.
+
+try:
+ import btree, uio, gc
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+N = 80
+
+# Create a BytesIO but don't keep a reference to it.
+db = btree.open(uio.BytesIO(), pagesize=512)
+
+# Overwrite lots of the Python stack to make sure no reference to the BytesIO remains.
+x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+
+# Write lots of key/value pairs, which fill up the DB and also allocate temporary heap
+# memory due to the string addition, and do a GC collect to verify that the BytesIO
+# is not collected.
+for i in range(N):
+ db[b"thekey" + str(i)] = b"thelongvalue" + str(i)
+ print(db[b"thekey" + str(i)])
+ gc.collect()