@@ -84,6 +84,40 @@ def target(conn, ev):
84
84
proc .join (3 )
85
85
assert proc .exitcode == 0
86
86
87
+ @pytest .mark .parametrize ("max_connections" , [2 , None ])
88
+ def test_release_parent_connection_from_pool_in_child_process (
89
+ self , max_connections , master_host
90
+ ):
91
+ """
92
+ A connection owned by a parent should not decrease the _created_connections
93
+ counter in child when released - when the child process starts to use the
94
+ pool it resets all the counters that have been set in the parent process.
95
+ """
96
+
97
+ pool = ConnectionPool .from_url (
98
+ f"redis://{ master_host [0 ]} :{ master_host [1 ]} " ,
99
+ max_connections = max_connections ,
100
+ )
101
+
102
+ parent_conn = pool .get_connection ("ping" )
103
+
104
+ def target (pool , parent_conn ):
105
+ with exit_callback (pool .disconnect ):
106
+ child_conn = pool .get_connection ("ping" )
107
+ assert child_conn .pid != parent_conn .pid
108
+ pool .release (child_conn )
109
+ assert pool ._created_connections == 1
110
+ assert child_conn in pool ._available_connections
111
+ pool .release (parent_conn )
112
+ assert pool ._created_connections == 1
113
+ assert child_conn in pool ._available_connections
114
+ assert parent_conn not in pool ._available_connections
115
+
116
+ proc = multiprocessing .Process (target = target , args = (pool , parent_conn ))
117
+ proc .start ()
118
+ proc .join (3 )
119
+ assert proc .exitcode == 0
120
+
87
121
@pytest .mark .parametrize ("max_connections" , [1 , 2 , None ])
88
122
def test_pool (self , max_connections , master_host ):
89
123
"""
0 commit comments