Повысить устойчивость восьмого уровня к задержкам

This commit is contained in:
2026-08-18 03:40:40 +03:00
parent 9e418df184
commit de0f8b891f
3 changed files with 29 additions and 9 deletions
@@ -43,19 +43,39 @@ public final class LevelEightPlaythroughTest {
}
}
@Test
public void intendedRouteSurvivesStressedDecisionScheduling() {
try (ActivityScenario<MainActivity> activity = ActivityScenario.launch(MainActivity.class)) {
LevelEightScenario.Result result = new LevelEightScenario()
.completeIntendedRoute(driver(activity, 96L), 20_000L);
assertTrue("Stressed scheduling: " + result.diagnostic(), result.completed());
assertEquals("The stressed intended route is deathless", 0, result.deaths());
}
}
private static AndroidDriver driver(ActivityScenario<MainActivity> activity) {
return driver(activity, 0L);
}
private static AndroidDriver driver(ActivityScenario<MainActivity> activity,
long extraDecisionDelayMillis) {
final GameView[] view = new GameView[1];
activity.onActivity(mainActivity -> view[0] = mainActivity.gameViewForAutomation());
return new AndroidDriver(InstrumentationRegistry.getInstrumentation(), view[0]);
return new AndroidDriver(InstrumentationRegistry.getInstrumentation(), view[0],
extraDecisionDelayMillis);
}
private static final class AndroidDriver implements LevelPlaytestBot.Driver {
private final Instrumentation instrumentation;
private final GameView gameView;
private final long extraDecisionDelayMillis;
AndroidDriver(Instrumentation instrumentation, GameView gameView) {
AndroidDriver(Instrumentation instrumentation, GameView gameView,
long extraDecisionDelayMillis) {
this.instrumentation = instrumentation;
this.gameView = gameView;
this.extraDecisionDelayMillis = extraDecisionDelayMillis;
}
@Override
@@ -80,7 +100,7 @@ public final class LevelEightPlaythroughTest {
@Override
public void waitForNextDecision(long millis) {
try {
Thread.sleep(millis);
Thread.sleep(millis + extraDecisionDelayMillis);
} catch (InterruptedException interrupted) {
Thread.currentThread().interrupt();
throw new AssertionError("Level-8 bot interrupted", interrupted);