How to keep alive Appium session for long time - webdriver

I need to wait in the middle of my test for 5 minutes but the Appium session has default newCommandTimeout of 60s. and I get exception in the next command that my session is timeout.
AndroidDriver appiumDriver = new AndroidDriver(new URL(getMcmUrl()), capabilities);
Thread.sleep(5*60*1000); // 5 minutes sleep time
appiumDriver.executeScript("...")

newCommandTimeout:
How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session
in case that the timeout is 60s, you need to execute any command at least once in a minute, to keep the session alive.
For example, this is how sleep for 5 minutes should look like
for (int i = 0; i < 5; i++) {
driver.getOrientation(); // execute some command to keep the session alive
Thread.sleep(59*1000); // wake up before session expired
}
Read this article for more information
https://l18.me/how-to-keep-alive-appium-driver-da9227b2fa

In your DesiredCapabilities add newCommandTimeout capabilities.
DesiredCapabilities caps=new DesiredCapabilities();
//other desired caps
//add the following line
caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 300);
//then define your driver here
AppiumDriver<MobileElement> driver= new AndroidDriver(new URL(getMcmUrl()), caps);
newCommandTimeout means How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session.
300 sec = 5 minutes

Have you considered and dismissed overriding the newCommandTimeout? That will certainly work, but has downsides.

try using this command,
"cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "100");"
By this command the appium server will wait for 100 seconds for a command before shutting down. You can increase the timeout for your preference.

Related

Why does Vertx throws a warning even with blocking attribute?

I have a Quarkus application where I use the event bus.
the code in question looks like this:
#ConsumeEvent(value = "execution-request", blocking = true)
#Transactional
#TransactionConfiguration(timeout = 3600)
public void consume(final Message<ExecutionRequest> msg) {
try {
execute(...);
} catch (final Exception e) {
// some logging
}
}
private void execute(...)
throws InterruptedException {
// it actually runs a long running task, but for
// this example this has the same effect
Thread.sleep(65000);
}
Why do I still get a
WARN [io.ver.cor.imp.BlockedThreadChecker] (vertx-blocked-thread-checker) Thread Thread[vert.x-worker-thread-0,5,main] has been blocked for 63066 ms, time limit is 60000 ms: io.vertx.core.VertxException: Thread blocked
I'm I doing something wrong? Is the blocking parameter at the ConsumeEvent annotation not enough to let that handle in a separate Worker?
Your annotation is working as designed; the method is running in a worker thread. You can tell by both the name of the thread "vert.x-worker-thread-0", and by the 60 second timeout before the warnings were logged. The eventloop thread only has a 3 second timeout, I believe.
The default Vert.x worker thread pool is not designed for "very" long running blocking code, as stated in their docs:
Warning:
Blocking code should block for a reasonable amount of time (i.e no more than a few seconds). Long blocking operations or polling operations (i.e a thread that spin in a loop polling events in a blocking fashion) are precluded. When the blocking operation lasts more than the 10 seconds, a message will be printed on the console by the blocked thread checker. Long blocking operations should use a dedicated thread managed by the application, which can interact with verticles using the event-bus or runOnContext
That message mentions blocking for more than 10 seconds triggers a warning, but I think that's a typo; the default is actually 60.
To avoid the warning, you'll need to create a dedicated WorkerExecutor (via vertx.createSharedWorkerExecutor) configured with a very high maxExcecuteTime. However, it does not appear you can tell the #ConsumeEvent annotation to use it instead of the default worker pool, so you'd need to manually create an event bus consumer, as well, or use a regular #ConsumeEvent annotation, but call workerExectur.executeBlocking inside of it.

firebase onDisconnect() is not fired when user lose connection

Hello React native community, I'm trying to use onDisconnect() in firebase but the problem is that the void isn't getting fired when the network loses its connection but it is working if I close the app or when the app crashes.
This code is working if Wi-Fi is on but it's not working at all if Wi-Fi is off..
firebase.database().ref('users/test/connected').onDisconnect().set(false)
Any ideas?
You can combine disconnect operations with connection status monitoring and server time stamps to build a user connection status system. On this system, each user stores data in a specific database location to alert the real-time database client to online. The client sets this location to true when it comes online and to time stamp when it disconnects. This timestamp indicates the last time the user was online.
Apps have a disconnect operation ahead of the user's online display, so that there is no contention if the client loses network connectivity before the two commands are sent to the server.
// since I can connect from multiple devices or browser tabs, we store each connection instance separately
// any time that connectionsRef's value is null (i.e. has no children) I am offline
var myConnectionsRef = firebase.database().ref('users/test/connections');
// stores the timestamp of my last disconnect (the last time I was seen online)
var lastOnlineRef = firebase.database().ref('users/test/lastOnline');
var connectedRef = firebase.database().ref('.info/connected');
connectedRef.on('value', function(snap) {
if (snap.val() === true) {
// We're connected (or reconnected)! Do anything here that should happen only if online (or on reconnect)
var con = myConnectionsRef.push();
// When I disconnect, remove this device
con.onDisconnect().remove();
// Add this device to my connections list
// this value could contain info about the device or a timestamp too
con.set(true);
// When I disconnect, update the last time I was seen online
lastOnlineRef.onDisconnect().set(firebase.database.ServerValue.TIMESTAMP);
}
});

WinRT/UWP is suspending rising on power off?

I am trying to save data before application (WinRT 8.1) close/sleep/minimze (or windows shutdown/restart in tablet with WIN10) using app suspending event.
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/suspend-an-app
However, it os not working on power off / shutdown WinRT/UWP: Is suspending action rising on long power off button holding?
The Suspending lifecycle event will fire in case of a normal OS shutdown - if you do Start -> Shut down.
This is unfortunately not the case with long power off button holding and restart button press, because both these are improper ways of shutting down your PC. Holding power button to shutdown essentially suddenly "cuts-down power" to the PC, which means the OS cannot respond to this and all unsaved data are lost. This method of shutting down a PC should be used only when something really bad happens and everything freezes. That is why the UWP app has no chance to run the suspending event handler in this case.
Is suspending action rising on long power off button holding?
System will shutdown forcibly with long press power off button. And the system could not make sure Current user session is finished. So the suspending event handler could not be invoked correctly.
From Windows 10 universal Windows platform (UWP) app lifecycle:
Current user session is based on Windows logon. As long as the current user hasn't logged off, shut down, or restarted Windows, the current user session persists across events such as lock screen authentication, switch-user, and so on.
So, before shut down, the app still in the Current user session. And Suspended will be invoked on power off(shut down).
Note, you can not test it in debug model within Visual Studio. Because when you shut down the system, Visual Studio will exit degbug model at first. The Suspended event will not be invoked as expect. You could verify with following code.
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var stringBulider = new StringBuilder();
var deferral = e.SuspendingOperation.GetDeferral();
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
Object value = localSettings.Values["exampleSetting"];
stringBulider.Append(value.ToString() + "/Next");
localSettings.Values["exampleSetting"] = stringBulider.ToString();
deferral.Complete();
}
Each time you shut down, the stringBulider will be append one at a time.

Long running php process with Doctrine

I created a Symfony 3 command that is expected to run for days (or even weeks). It uses Doctrine 2 for reading some initial data and for writing the execution status from time to time. The SQLs are expected to take few milliseconds.
My concern is that the whole process will eventually crash if the MySQL connection closes due to inactivity.
Question: is Doctrine keeping the database connection open between flush calls? Or, is it reconnecting every time flush is called?
AFAIK Symfony will open up a connection to the database the first time Doctrine is used in your app and close it when the HTTP request is sent (or if you specifically tell Doctrine to close it). Once connected, Doctrine will have the connection active until you explicitly close it (and will be active before, during and after flush())
In your case you should probably open and close the db connection explicitly when you need it. Something like the following code could solve your problem:
// When you need the DB
/**
* #var \Doctrine\DBAL\Connection $connection
*/
$connection = $this->get('doctrine')->getConnection();
// check if the connection is still active and if not connect to the db
if(!$connection->isConnected()) {
$connection->connect();
}
// Your code to update the database goes after this.
your code
// Once you're done with the db update - close the connection.
if($connection->isConnected()) {
$connection->close(); // close the db connection;
}
This will avoid db connection timeouts and etc, however you should be quite careful with memory leaks if this script will be running as long as you're saying. Using Symfony might not be the best approach to this problem.
You can simply ping the connection every 1000 seconds, less than MySQL's connection limit.
Best thing to do would be to run a supervising process (eg. supervisord), which would restart the process as soon as your app stops. Then you can simply tell your script to exit before the connection is dropped (as it's a configured value, in MySQL for instance it's the wait_timeout variable). Supervising process will notice your app is dead and will restart it.

“Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.”

{
DataSet obj= new DataSet();
SqlParameter[] sqlParams = new SqlParameter[2];
sqlParams[0] = new SqlParameter("#val", SqlDbType.Int);
sqlParams[0].Value = val;
sqlParams[1] = new SqlParameter("#val1", SqlDbType.Int);
sqlParams[1].Value = val1;
return DataAccessHelper.DataAccessHelper.SqlHelper.ExecuteDataset(connection, CommandType.StoredProcedure, "sp", sqlParams);
}
i have set connection timeout in web config and i can't use command timeout in c# ,am not using sqlcommand .my code stored procedure is taking around 2 mins so am getting this error.please suggest me to solve this issue
This is a try for help, I am not absolutely sure if this is the real issue, or a very bad database design and or bad query request.
If your query takes 2min, you may have felt on the session lock and other page request simple gets time out...
What I mean. The session (when you use it) is lock every page action for each user. Now if a user block the page for 2 min, every other request takes 2+2 min to complete, and so on... and eventually you have time outs.
Disable the session for this part of calculations, or send it to background thread and just show the results, or make better sql query...
Some more to read:
ASP.NET Server does not process pages asynchronously
Web app blocked while processing another web app on sharing same session

Resources