@@ -115,26 +115,6 @@ public void async_IfBotDelay_ThenClientStalls() {
115115 environment .runGame ();
116116 }
117117
118- @ Test
119- public void async_IfUnsafe_ThenBotProceedsImmediately () {
120- SynchronizationEnvironment environment = new SynchronizationEnvironment ();
121- environment .configuration .async = true ;
122- environment .configuration .asyncUnsafe = true ;
123- environment .configuration .maxFrameDurationMs = 100 ;
124- environment .configuration .logVerbosely = true ;
125-
126- environment .onFrame (1 , () -> {
127- assertEquals ("Bot should be observing frame 1" , 1 , environment .bwClient .getGame ().getFrameCount ());
128- assertEquals ("Live game should be observing frame 1" , 1 , environment .liveGameData ().getFrameCount ());
129- environment .liveGameData ().setFps (12345 );
130- assertEquals ("Bot should be observing live game" , 12345 , environment .bwClient .getGame ().getFPS ());
131- sleepUnchecked (50 );
132- assertFalse ("Bot should be observing frame buffer" , 12345 == environment .bwClient .getGame ().getFPS ());
133- });
134-
135- environment .runGame (3 );
136- }
137-
138118 @ Test
139119 public void async_IfFrameZeroWaitsEnabled_ThenAllowInfiniteTime () {
140120 SynchronizationEnvironment environment = new SynchronizationEnvironment ();
@@ -150,7 +130,7 @@ public void async_IfFrameZeroWaitsEnabled_ThenAllowInfiniteTime() {
150130 assertEquals ("Bot should not be behind the live game" , 0 , environment .bwClient .framesBehind ());
151131 });
152132
153- environment .runGame ();
133+ environment .runGame (2 );
154134 }
155135
156136 @ Test
@@ -168,25 +148,7 @@ public void async_IfFrameZeroWaitsDisabled_ThenClientBuffers() {
168148 assertEquals ("Bot should be behind the live game" , 2 , environment .bwClient .framesBehind ());
169149 });
170150
171- environment .runGame ();
172- }
173-
174- @ Test
175- public void async_MeasurePerformance_TotalFrameDuration () {
176- final int frames = 10 ;
177- final int frameSleep = 20 ;
178- SynchronizationEnvironment environment = new SynchronizationEnvironment ();
179- environment .configuration .async = true ;
180- environment .configuration .unlimitedFrameZero = true ;
181- environment .configuration .maxFrameDurationMs = frameSleep + 20 ;
182- IntStream .range (0 , frames ).forEach (i -> environment .onFrame (i , () -> {
183- sleepUnchecked (frameSleep );
184- }));
185- environment .runGame (frames );
186-
187- // Assume copying accounts for almost all the frame time except what the bot uses
188- double meanCopy = environment .metrics ().copyingToBuffer .avgValue ;
189- assertWithin ("Total frame duration: Average" , environment .metrics ().totalFrameDuration .avgValue , meanCopy + frameSleep , MS_MARGIN );
151+ environment .runGame (2 );
190152 }
191153
192154 @ Test
@@ -199,10 +161,10 @@ public void async_MeasurePerformance_CopyingToBuffer() {
199161 final double maxObserved = 15 ;
200162 final double meanObserved = (minObserved + maxObserved ) / 2 ;
201163 final double rangeObserved = (maxObserved - minObserved ) / 2 ;
202- assertWithin ("Copy to buffer: minimum" , environment .metrics ().copyingToBuffer .minValue , meanObserved , rangeObserved );
203- assertWithin ("Copy to buffer: maximum" , environment .metrics ().copyingToBuffer .maxValue , meanObserved , rangeObserved );
204- assertWithin ("Copy to buffer: average" , environment .metrics ().copyingToBuffer .avgValue , meanObserved , rangeObserved );
205- assertWithin ("Copy to buffer: previous" , environment .metrics ().copyingToBuffer .lastValue , meanObserved , rangeObserved );
164+ assertWithin ("Copy to buffer: minimum" , environment .metrics ().copyingToBuffer .runningTotal . min , meanObserved , rangeObserved );
165+ assertWithin ("Copy to buffer: maximum" , environment .metrics ().copyingToBuffer .runningTotal . max , meanObserved , rangeObserved );
166+ assertWithin ("Copy to buffer: average" , environment .metrics ().copyingToBuffer .runningTotal . mean , meanObserved , rangeObserved );
167+ assertWithin ("Copy to buffer: previous" , environment .metrics ().copyingToBuffer .runningTotal . last , meanObserved , rangeObserved );
206168 }
207169
208170 @ Test
@@ -214,25 +176,25 @@ public void async_MeasurePerformance_FrameBufferSizeAndFramesBehind() {
214176 environment .configuration .maxFrameDurationMs = 20 ;
215177
216178 environment .onFrame (5 , () -> {
217- assertWithin ("5: Frame buffer average" , 0 , environment .metrics ().frameBufferSize .avgValue , 0.1 );
218- assertWithin ("5: Frame buffer minimum" , 0 , environment .metrics ().frameBufferSize .minValue , 0.1 );
219- assertWithin ("5: Frame buffer maximum" , 0 , environment .metrics ().frameBufferSize .maxValue , 0.1 );
220- assertWithin ("5: Frame buffer previous" , 0 , environment .metrics ().frameBufferSize .lastValue , 0.1 );
221- assertWithin ("5: Frames behind average" , 0 , environment .metrics ().framesBehind .avgValue , 0.1 );
222- assertWithin ("5: Frames behind minimum" , 0 , environment .metrics ().framesBehind .minValue , 0.1 );
223- assertWithin ("5: Frames behind maximum" , 0 , environment .metrics ().framesBehind .maxValue , 0.1 );
224- assertWithin ("5: Frames behind previous" , 0 , environment .metrics ().framesBehind .lastValue , 0.1 );
179+ assertWithin ("5: Frame buffer average" , 0 , environment .metrics ().frameBufferSize .runningTotal . mean , 0.1 );
180+ assertWithin ("5: Frame buffer minimum" , 0 , environment .metrics ().frameBufferSize .runningTotal . min , 0.1 );
181+ assertWithin ("5: Frame buffer maximum" , 0 , environment .metrics ().frameBufferSize .runningTotal . max , 0.1 );
182+ assertWithin ("5: Frame buffer previous" , 0 , environment .metrics ().frameBufferSize .runningTotal . last , 0.1 );
183+ assertWithin ("5: Frames behind average" , 0 , environment .metrics ().framesBehind .runningTotal . mean , 0.1 );
184+ assertWithin ("5: Frames behind minimum" , 0 , environment .metrics ().framesBehind .runningTotal . min , 0.1 );
185+ assertWithin ("5: Frames behind maximum" , 0 , environment .metrics ().framesBehind .runningTotal . max , 0.1 );
186+ assertWithin ("5: Frames behind previous" , 0 , environment .metrics ().framesBehind .runningTotal . last , 0.1 );
225187 sleepUnchecked (200 );
226188 });
227189 environment .onFrame (6 , () -> {
228- assertWithin ("6: Frame buffer average" , 1 / 6.0 + 2 / 7.0 , environment .metrics ().frameBufferSize .avgValue , 0.1 );
229- assertWithin ("6: Frame buffer minimum" , 0 , environment .metrics ().frameBufferSize .minValue , 0.1 );
230- assertWithin ("6: Frame buffer maximum" , 2 , environment .metrics ().frameBufferSize .maxValue , 0.1 );
231- assertWithin ("6: Frame buffer previous" , 2 , environment .metrics ().frameBufferSize .lastValue , 0.1 );
232- assertWithin ("6: Frames behind average" , 1 / 6.0 , environment .metrics ().framesBehind .avgValue , 0.1 );
233- assertWithin ("6: Frames behind minimum" , 0 , environment .metrics ().framesBehind .minValue , 0.1 );
234- assertWithin ("6: Frames behind maximum" , 1 , environment .metrics ().framesBehind .maxValue , 0.1 );
235- assertWithin ("6: Frames behind previous" , 1 , environment .metrics ().framesBehind .lastValue , 0.1 );
190+ assertWithin ("6: Frame buffer average" , 1 / 6.0 + 2 / 7.0 , environment .metrics ().frameBufferSize .runningTotal . mean , 0.1 );
191+ assertWithin ("6: Frame buffer minimum" , 0 , environment .metrics ().frameBufferSize .runningTotal . min , 0.1 );
192+ assertWithin ("6: Frame buffer maximum" , 2 , environment .metrics ().frameBufferSize .runningTotal . max , 0.1 );
193+ assertWithin ("6: Frame buffer previous" , 2 , environment .metrics ().frameBufferSize .runningTotal . last , 0.1 );
194+ assertWithin ("6: Frames behind average" , 1 / 6.0 , environment .metrics ().framesBehind .runningTotal . mean , 0.1 );
195+ assertWithin ("6: Frames behind minimum" , 0 , environment .metrics ().framesBehind .runningTotal . min , 0.1 );
196+ assertWithin ("6: Frames behind maximum" , 1 , environment .metrics ().framesBehind .runningTotal . max , 0.1 );
197+ assertWithin ("6: Frames behind previous" , 1 , environment .metrics ().framesBehind .runningTotal . last , 0.1 );
236198 });
237199
238200 environment .runGame (8 );
@@ -256,36 +218,26 @@ public void MeasurePerformance_BotResponse() {
256218 sleepUnchecked (100 );
257219 });
258220 environment .onFrame (2 , () -> {
259- assertWithin ("2: Bot response average" , 100 , environment .metrics ().botResponse .avgValue , MS_MARGIN );
260- assertWithin ("2: Bot response minimum" , 100 , environment .metrics ().botResponse .minValue , MS_MARGIN );
261- assertWithin ("2: Bot response maximum" , 100 , environment .metrics ().botResponse .maxValue , MS_MARGIN );
262- assertWithin ("2: Bot response previous" , 100 , environment .metrics ().botResponse .lastValue , MS_MARGIN );
221+ assertWithin ("2: Bot response average" , 100 , environment .metrics ().botResponse .runningTotal . mean , MS_MARGIN );
222+ assertWithin ("2: Bot response minimum" , 100 , environment .metrics ().botResponse .runningTotal . min , MS_MARGIN );
223+ assertWithin ("2: Bot response maximum" , 100 , environment .metrics ().botResponse .runningTotal . max , MS_MARGIN );
224+ assertWithin ("2: Bot response previous" , 100 , environment .metrics ().botResponse .runningTotal . last , MS_MARGIN );
263225 sleepUnchecked (300 );
264226 });
265227 environment .onFrame (3 , () -> {
266- assertWithin ("3: Bot response average" , 200 , environment .metrics ().botResponse .avgValue , MS_MARGIN );
267- assertWithin ("3: Bot response minimum" , 100 , environment .metrics ().botResponse .minValue , MS_MARGIN );
268- assertWithin ("3: Bot response maximum" , 300 , environment .metrics ().botResponse .maxValue , MS_MARGIN );
269- assertWithin ("3: Bot response previous" , 300 , environment .metrics ().botResponse .lastValue , MS_MARGIN );
228+ assertWithin ("3: Bot response average" , 200 , environment .metrics ().botResponse .runningTotal . mean , MS_MARGIN );
229+ assertWithin ("3: Bot response minimum" , 100 , environment .metrics ().botResponse .runningTotal . min , MS_MARGIN );
230+ assertWithin ("3: Bot response maximum" , 300 , environment .metrics ().botResponse .runningTotal . max , MS_MARGIN );
231+ assertWithin ("3: Bot response previous" , 300 , environment .metrics ().botResponse .runningTotal . last , MS_MARGIN );
270232 sleepUnchecked (200 );
271233 });
272234
273235 environment .runGame (4 );
274236
275- assertWithin ("Final: Bot response average" , 200 , environment .metrics ().botResponse .avgValue , MS_MARGIN );
276- assertWithin ("Final: Bot response minimum" , 100 , environment .metrics ().botResponse .minValue , MS_MARGIN );
277- assertWithin ("Final: Bot response maximum" , 300 , environment .metrics ().botResponse .maxValue , MS_MARGIN );
278- assertWithin ("Final: Bot response previous" , 200 , environment .metrics ().botResponse .lastValue , MS_MARGIN );
279- }
280-
281- @ Test
282- public void MeasurePerformance_BwapiResponse () {
283- final long bwapiDelayMs = 50 ;
284- SynchronizationEnvironment environment = new SynchronizationEnvironment ();
285- environment .setBwapiDelayMs (bwapiDelayMs );
286- environment .runGame ();
287- System .out .println (environment .metrics ());
288- assertWithin ("BWAPI Response: Average" , environment .metrics ().bwapiResponse .avgValue , bwapiDelayMs , MS_MARGIN );
237+ assertWithin ("Final: Bot response average" , 200 , environment .metrics ().botResponse .runningTotal .mean , MS_MARGIN );
238+ assertWithin ("Final: Bot response minimum" , 100 , environment .metrics ().botResponse .runningTotal .min , MS_MARGIN );
239+ assertWithin ("Final: Bot response maximum" , 300 , environment .metrics ().botResponse .runningTotal .max , MS_MARGIN );
240+ assertWithin ("Final: Bot response previous" , 200 , environment .metrics ().botResponse .runningTotal .last , MS_MARGIN );
289241 }
290242
291243 @ Test
@@ -298,8 +250,8 @@ public void MeasurePerformance_BotIdle() {
298250 environment .configuration .unlimitedFrameZero = true ;
299251 environment .setBwapiDelayMs (bwapiDelayMs );
300252 environment .runGame (frames );
301- double expected = environment .metrics ().copyingToBuffer .avgValue + bwapiDelayMs ;
302- assertWithin ("Bot Idle: Average" , environment .metrics ().botIdle .avgValue , expected , MS_MARGIN );
253+ double expected = environment .metrics ().copyingToBuffer .runningTotal . mean + bwapiDelayMs ;
254+ assertWithin ("Bot Idle: Average" , environment .metrics ().botIdle .runningTotal . mean , expected , MS_MARGIN );
303255 }
304256
305257 @ Test
@@ -315,10 +267,10 @@ public void async_MeasurePerformance_IntentionallyBlocking() {
315267 });
316268 environment .onFrame (2 , () -> {
317269 assertWithin (
318- "2: Intentionally blocking previous" ,
319- environment .metrics ().intentionallyBlocking .lastValue ,
320- frameDelayMs - environment .configuration .asyncFrameBufferCapacity * environment .configuration .maxFrameDurationMs ,
321- MS_MARGIN );
270+ "2: Intentionally blocking previous" ,
271+ environment .metrics ().intentionallyBlocking .runningTotal . last ,
272+ frameDelayMs - environment .configuration .asyncFrameBufferCapacity * environment .configuration .maxFrameDurationMs ,
273+ MS_MARGIN );
322274 sleepUnchecked (100 );
323275 });
324276 environment .runGame (3 );
0 commit comments