@@ -122,4 +122,43 @@ public function testCancel(): void
122
122
], $ logger ->getMessages ());
123
123
}
124
124
125
+ public function testCancelAll (): void
126
+ {
127
+ $ logger = new RunnableQueueLoggerStub ();
128
+ $ queue = new RunnableQueue ($ logger , 4 );
129
+ $ one = new RunnableStub ('1 ' );
130
+ $ two = new RunnableStub ('2 ' );
131
+ $ three = new RunnableStub ('3 ' );
132
+ $ queue ->queue ($ one , 3 );
133
+ $ queue ->queue ($ two , 2 );
134
+ $ queue ->queue ($ three , 3 );
135
+
136
+ $ this ->assertSame (5 , $ queue ->getQueueSize ());
137
+ $ this ->assertSame (3 , $ queue ->getRunningSize ());
138
+
139
+ $ queue ->cancelAll ();
140
+ $ this ->assertSame (0 , $ queue ->getQueueSize ());
141
+ $ this ->assertSame (0 , $ queue ->getRunningSize ());
142
+
143
+ $ this ->assertSame ([
144
+ 0 => 'Queue not full - looking at first item in the queue ' ,
145
+ 1 => 'Removing top item from queue - new size is 3 ' ,
146
+ 2 => 'Running process 1 ' ,
147
+ 3 => 'Queue not full - looking at first item in the queue ' ,
148
+ 4 => 'Canot remote first item from the queue - it has size 2, current queue size is 3, new size would be 5 ' ,
149
+ 5 => 'Queue not full - looking at first item in the queue ' ,
150
+ 6 => 'Canot remote first item from the queue - it has size 2, current queue size is 3, new size would be 5 ' ,
151
+ 7 => 'Process 1 finished unsuccessfully: Runnable 1 canceled ' ,
152
+ 8 => 'Queue not full - looking at first item in the queue ' ,
153
+ 9 => 'Removing top item from queue - new size is 2 ' ,
154
+ 10 => 'Running process 2 ' ,
155
+ 11 => 'Process 2 finished unsuccessfully: Runnable 2 canceled ' ,
156
+ 12 => 'Queue not full - looking at first item in the queue ' ,
157
+ 13 => 'Removing top item from queue - new size is 3 ' ,
158
+ 14 => 'Running process 3 ' ,
159
+ 15 => 'Process 3 finished unsuccessfully: Runnable 3 canceled ' ,
160
+ 16 => 'Queue empty ' ,
161
+ ], $ logger ->getMessages ());
162
+ }
163
+
125
164
}
0 commit comments