@@ -171,3 +171,43 @@ def test_chunked_processing_consistency(self):
171171
172172 expected = list (range (1 , 101 )) # [1, 2, 3, ..., 100]
173173 assert result == expected
174+
175+ def test_buffer_with_two_maps (self ):
176+ """Test that buffer function works correctly with two sequential map operations."""
177+ # Create a pipeline with two map operations and buffering
178+ data = list (range (10 ))
179+
180+ # Track execution order to verify buffering behavior
181+ execution_order = []
182+
183+ def first_map (x ):
184+ execution_order .append (f"first_map({ x } )" )
185+ return x * 2
186+
187+ def second_map (x ):
188+ execution_order .append (f"second_map({ x } )" )
189+ return x + 1
190+
191+ # Apply buffering with 2 workers between two map operations
192+ result = (
193+ Pipeline (data )
194+ .transform (lambda t : t .map (first_map ))
195+ .buffer (2 ) # Buffer with 2 workers
196+ .transform (lambda t : t .map (second_map ))
197+ .to_list ()
198+ )
199+
200+ # Verify the final result is correct
201+ expected = [(x * 2 ) + 1 for x in range (10 )] # [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
202+ assert result == expected
203+
204+ # Verify both map operations were called for each element
205+ assert len ([call for call in execution_order if "first_map" in call ]) == 10
206+ assert len ([call for call in execution_order if "second_map" in call ]) == 10
207+
208+ # Verify all expected values were processed
209+ first_map_values = [int (call .split ("(" )[1 ].split (")" )[0 ]) for call in execution_order if "first_map" in call ]
210+ second_map_values = [int (call .split ("(" )[1 ].split (")" )[0 ]) for call in execution_order if "second_map" in call ]
211+
212+ assert sorted (first_map_values ) == list (range (10 ))
213+ assert sorted (second_map_values ) == [x * 2 for x in range (10 )]
0 commit comments