@@ -100,3 +100,48 @@ func TestSubscriber_RunCatchup(t *testing.T) {
100100 assert .True (t , sub .HasReachedHead ())
101101 })
102102}
103+
104+ func TestSubscriber_RunSubscription_InlineDoesNotPrematurelyReachHead (t * testing.T ) {
105+ ctx , cancel := context .WithCancel (t .Context ())
106+ defer cancel ()
107+
108+ mockHandler := new (MockSubscriberHandler )
109+ mockClient := testmocks .NewMockClient (t )
110+
111+ sub := NewSubscriber (SubscriberConfig {
112+ Client : mockClient ,
113+ Logger : zerolog .Nop (),
114+ Handler : mockHandler ,
115+ Namespaces : [][]byte {[]byte ("ns" )},
116+ StartHeight : 100 ,
117+ DABlockTime : time .Hour ,
118+ })
119+
120+ subCh := make (chan datypes.SubscriptionEvent , 2 )
121+ mockClient .EXPECT ().
122+ Subscribe (mock .Anything , []byte ("ns" ), false ).
123+ Return ((<- chan datypes.SubscriptionEvent )(subCh ), nil ).
124+ Once ()
125+
126+ mockHandler .On ("HandleEvent" , mock .Anything , datypes.SubscriptionEvent {
127+ Height : 101 ,
128+ Blobs : [][]byte {[]byte ("h101" )},
129+ }, false ).Return (nil ).Once ()
130+ mockHandler .On ("HandleEvent" , mock .Anything , datypes.SubscriptionEvent {
131+ Height : 100 ,
132+ Blobs : [][]byte {[]byte ("h100" )},
133+ }, true ).Return (nil ).Once ()
134+
135+ subCh <- datypes.SubscriptionEvent {Height : 101 , Blobs : [][]byte {[]byte ("h101" )}}
136+ subCh <- datypes.SubscriptionEvent {Height : 100 , Blobs : [][]byte {[]byte ("h100" )}}
137+ close (subCh )
138+
139+ err := sub .runSubscription (ctx )
140+ assert .Error (t , err )
141+ if err != nil {
142+ assert .Contains (t , err .Error (), "subscription channel closed" )
143+ }
144+ assert .False (t , sub .HasReachedHead ())
145+ assert .Equal (t , uint64 (101 ), sub .LocalDAHeight ())
146+ assert .Equal (t , uint64 (101 ), sub .HighestSeenDAHeight ())
147+ }
0 commit comments