@@ -81,7 +81,7 @@ func (suite *FixedFIFOTestSuite) TestEnqueueFullCapacitySingleGR() {
8181func (suite * FixedFIFOTestSuite ) TestEnqueueListenerToExpireSingleGR () {
8282 var (
8383 uselessChan = make (chan interface {})
84- value = "my-test-value"
84+ value = "my-test-value"
8585 )
8686
8787 // let Enqueue knows there is a channel to send the next item instead of enqueueing it into the queue
@@ -98,6 +98,7 @@ func (suite *FixedFIFOTestSuite) TestEnqueueListenerToExpireSingleGR() {
9898// TestEnqueueLenMultipleGR enqueues elements concurrently
9999//
100100// Detailed steps:
101+ //
101102// 1 - Enqueue totalGRs concurrently (from totalGRs different GRs)
102103// 2 - Verifies the len, it should be equal to totalGRs
103104// 3 - Verifies that all elements from 0 to totalGRs were enqueued
@@ -269,6 +270,7 @@ func (suite *FixedFIFOTestSuite) TestDequeueClosedChannelSingleGR() {
269270// TestDequeueMultipleGRs dequeues elements concurrently
270271//
271272// Detailed steps:
273+ //
272274// 1 - Enqueues totalElementsToEnqueue consecutive integers
273275// 2 - Dequeues totalElementsToDequeue concurrently from totalElementsToDequeue GRs
274276// 3 - Verifies the final len, should be equal to totalElementsToEnqueue - totalElementsToDequeue
@@ -376,6 +378,39 @@ func (suite *FixedFIFOTestSuite) TestDequeueOrWaitForNextElementWithEmptyQueue()
376378 }
377379}
378380
381+ // calling DequeueOrWaitForNextElement with empty queue, then adding an item directly into queue's internal channel
382+ func (suite * FixedFIFOTestSuite ) TestDequeueOrWaitForNextElementWithStuckWaitChan () {
383+ var (
384+ dummyValue = "dummyValue"
385+ doneChan = make (chan struct {})
386+ )
387+
388+ // consumer
389+ go func (queue * FixedFIFO , expectedValue interface {}, done chan struct {}) {
390+ item , err := queue .DequeueOrWaitForNextElement ()
391+ suite .NoError (err )
392+ suite .Equal (expectedValue , item )
393+
394+ done <- struct {}{}
395+ }(suite .fifo , dummyValue , doneChan )
396+
397+ // a second should be enough for the consumer to start consuming ...
398+ time .Sleep (time .Second )
399+
400+ // add an item (enqueue) directly into queue's internal channel
401+ suite .fifo .queue <- dummyValue
402+
403+ ctx , cancel := context .WithTimeout (context .Background (), time .Second )
404+ defer cancel ()
405+
406+ select {
407+ case <- doneChan :
408+
409+ case <- ctx .Done ():
410+ suite .Fail ("too much time waiting ..." )
411+ }
412+ }
413+
379414// single GR calling DequeueOrWaitForNextElement (WaitForNextElementChanCapacity + 1) times, last one should return error
380415func (suite * FixedFIFOTestSuite ) TestDequeueOrWaitForNextElementWithFullWaitingChannel () {
381416 // enqueue WaitForNextElementChanCapacity listeners to future enqueued elements
@@ -554,4 +589,4 @@ func (suite *FixedFIFOTestSuite) TestContextAlreadyCanceled() {
554589 case <- time .After (2 * time .Second ):
555590 suite .Fail ("DequeueOrWaitForNextElementContext did not return immediately after context was canceled" )
556591 }
557- }
592+ }
0 commit comments