summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatus Valo <matusvalo@gmail.com>2021-10-05 14:02:47 +0200
committerMatus Valo <matusvalo@gmail.com>2021-10-05 14:02:47 +0200
commit28c8984e7d8f29daf03942a23a700feefc7172c4 (patch)
treede57eed5e5a36fec1d8079459a3c3efd85cd050e
parent96ca00f05f264947e9256225a83a35ba3297cdfe (diff)
downloadkombu-28c8984e7d8f29daf03942a23a700feefc7172c4.tar.gz
Added unittests for #1394
-rw-r--r--t/unit/test_pidbox.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/t/unit/test_pidbox.py b/t/unit/test_pidbox.py
index 7a1b9b1f..7c47eae2 100644
--- a/t/unit/test_pidbox.py
+++ b/t/unit/test_pidbox.py
@@ -1,6 +1,7 @@
import socket
import warnings
from unittest.mock import Mock, patch
+from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
import pytest
@@ -338,3 +339,42 @@ class test_Mailbox:
m = consumer.queues[0].get()
if m:
return m.payload
+
+
+GLOBAL_PIDBOX = None
+
+
+def getoid():
+ return GLOBAL_PIDBOX.oid
+
+
+class test_PidboxOid:
+ """Unittests checking oid consistency of Pidbox"""
+
+ def setup(self):
+ global GLOBAL_PIDBOX
+ GLOBAL_PIDBOX = pidbox.Mailbox('unittest_mailbox')
+
+ def test_oid_consistency(self):
+ """Tests that oid is consistent in single process"""
+ m1 = pidbox.Mailbox('mailbox1')
+ m2 = pidbox.Mailbox('mailbox2')
+ assert m1.oid == m1.oid
+ assert m2.oid == m2.oid
+ assert m1.oid != m2.oid
+
+ def test_subprocess_oid(self):
+ """Tests that subprocess will not share oid with parent process."""
+ oid = GLOBAL_PIDBOX.oid
+ with ProcessPoolExecutor() as e:
+ res = e.submit(getoid)
+ subprocess_oid = res.result()
+ assert subprocess_oid != oid
+
+ def test_thread_oid(self):
+ """Tests that threads will not share oid."""
+ oid = GLOBAL_PIDBOX.oid
+ with ThreadPoolExecutor() as e:
+ res = e.submit(getoid)
+ subprocess_oid = res.result()
+ assert subprocess_oid != oid