@@ -627,26 +627,33 @@ defmodule GenStageTest do
627
627
describe "demand" do
628
628
test "can be set to :accumulate on init" do
629
629
{ :ok , producer } = Counter . start_link ( { :producer , 0 , demand: :accumulate } )
630
+ assert GenStage . demand ( producer ) == :accumulate
630
631
{ :ok , consumer } = Forwarder . start_link ( { :consumer , self ( ) } )
631
632
GenStage . sync_subscribe ( consumer , to: producer , max_demand: 4 , min_demand: 0 )
632
633
refute_received { :consumed , [ 0 , 1 , 2 , 3 ] }
633
634
GenStage . demand ( producer , :forward )
635
+ assert GenStage . demand ( producer ) == :forward
634
636
assert_receive { :consumed , [ 0 , 1 , 2 , 3 ] }
635
637
end
636
638
637
639
test "can be set to :accumulate via API" do
638
640
{ :ok , producer } = Counter . start_link ( { :producer , 0 } )
641
+ assert GenStage . demand ( producer ) == :forward
639
642
GenStage . demand ( producer , :accumulate )
643
+ assert GenStage . demand ( producer ) == :accumulate
640
644
{ :ok , consumer } = Forwarder . start_link ( { :consumer , self ( ) } )
641
645
GenStage . sync_subscribe ( consumer , to: producer , max_demand: 4 , min_demand: 0 )
642
646
refute_received { :consumed , [ 0 , 1 , 2 , 3 ] }
643
647
GenStage . demand ( producer , :forward )
648
+ assert GenStage . demand ( producer ) == :forward
644
649
assert_receive { :consumed , [ 0 , 1 , 2 , 3 ] }
645
650
end
646
651
647
652
test "can be set to :forward via API before subscriptions" do
648
653
{ :ok , producer } = Counter . start_link ( { :producer , 0 , demand: :accumulate } )
654
+ assert GenStage . demand ( producer ) == :accumulate
649
655
GenStage . demand ( producer , :forward )
656
+ assert GenStage . demand ( producer ) == :forward
650
657
{ :ok , consumer } = Forwarder . start_link ( { :consumer , self ( ) } )
651
658
GenStage . sync_subscribe ( consumer , to: producer , max_demand: 4 , min_demand: 0 )
652
659
assert_receive { :consumed , [ 0 , 1 , 2 , 3 ] }
0 commit comments