Handle a frozen app correctly

Hi,

Does anyone have any ideas/tips to handle/fail tests correctly if the App being tested hangs/freezes?

In this particular scenario, the app freezes and the next Appium command is not received until approximately 7 minutes later.

Example
The messagesLoaded/noMessagesIndicatorLoaded methods are a waitForElement with 10 seconds set - So the test would normally fail quickly if the elements are not found, however Appium seems to sit and hang for a while due to the frozen app.

@Then("^I should see the job message details$")
fun i_should_see_the_job_message_details() {
    val jobMessagesPage=JobMessagesPage(getAppiumDriver())
    if(!jobMessagesPage.messagesLoaded){
        Assert.assertTrue(jobMessagesPage.noMessagesIndicatorLoaded, "Messages not loaded")
    }
}

If run on DeviceFarm, the app will not run testng @AfterSuite (and fail to produce a report) because according to the logs the server times out after 60 seconds and does not make it to the tearDown() method we have in the @AfterSuite which is also where our reports are produced.

FAILED CONFIGURATION: @AfterMethod tearDown([TestResult name=runScenario status=FAILURE method=AbstractTestNGCucumberTests.runScenario(cucumber.api.testng.PickleEventWrapper, cucumber.api.testng.CucumberFeatureWrapper)[pri:0, instance:com.skedulo.automation.mobile.tests.MessagesTest@448ff1a8] output={null}])
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'ip-192-168-10-5.us-west-2.compute.internal', ip: 'fe80:0:0:0:1486:baea:1c26:8b5%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '12.0.2'
Driver info: io.appium.java_client.ios.IOSDriver
Capabilities {app: /tmp/scratchtsazvy.scratch/..., autoAcceptAlerts: true, autoGrantPermissions: true, automationName: XCUITest, browserName: , bundleId: com.skedulo.app, databaseEnabled: false, derivedDataPath: /tmp/scratchtsazvy.scratch/..., deviceName: 00008020-001D358E0E50003A, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: false, platform: MAC, platformName: iOS, takesScreenshot: true, udid: 00008020-001D358E0E50003A, usePrebuiltWDA: true, webStorageEnabled: false}
Session ID: 7e254593-5c55-443b-9b6a-13d98ee079a0

I’m aware of the Capability flag newCommandTimeout, however if a new command is never received, Appium will just sit there and do nothing.

Basically, it would be nice to fail a test and force a restart if the app freezes and hangs.

Thanks for everyones time.