For Loop is not looping untill the given range in robot framework - robotframework

sleep till Rest api
FOR ${i} IN RANGE 20
Sleep 5s till rest api is available
${result} = Check Rest Api
Exit For Loop If ${result} == True
Log to Console try again in 5 sec
END
I am using For loop to sleep for some time until the api is available and exit from loop once it has got the response. For this I had stored the result of the keyword in a varibale and gave exit from loop when result becomes true. But, whats happening is first it waits for 5 seconds and checks the result and fails. After failing once it is not iterating and fails at checking the result itself.
Here when it goes through the second line in for loop ( ${result} = Check Rest Api ). The sleep time is not sufficient and it fails at that statement itself. What I am expecting is the loop should continue until it gets the response.

Related

Kernel cancelling a `input_request` at the end of the execution of a cell

I'm implementing a new Go kernel, using directly the ZMQ messages. But as an extra I want it to execute any bash command when a line is prefixed with !, similar to the usual ipython kernel.
One of the tricky parts seems to be bash scripts that take input -- there is no way (that I know of) to predict when I need to request input. So I took the following approach:
Whenever I execute a bash script, if it hasn't ended after 500ms (configurable), it issues an input_request.
If the kernel receives any input back (input_reply message), it writes the contents to the bash program's piped stdin (concurrently, not to block), and immediately issues another input_request.
Now at the end of the execution of the bash program, there is always the last input_request pending, and the corresponding widget expecting input from the user.
Jupyter doesn't drop the input_request after the execution of the cell ended, and requires the user to type enter and send an input_reply before another cell can be executed. It complains with "Cell not executed due to pending input"
Is there a way to cancel the input_request (the pending input) if the execution of the last cell already finished ?
Maybe there is some undocumented message that can be send once the bash program ends ?
Any other suggested approach ?
I know something similar works in colab.research.google.com, if I do:
!while read ii; do if [[ "${ii}" == "done" ]] ; then exit 0; fi ; echo "Input: $ii"; done
It correctly asks for inputs, and closes the last one.
But I'm not sure how that is achieved.
Jupyter's ipython notebook doesn't seem to have that smarts though, at least here the line above just locks. I suppose it never sends a input_request message.
many thanks in advance!

Verify time with 3 seconds buffer

Get Current Audio Upload Time
${time}= Get Current Date
${converted-time}= Convert Date ${time} result_format=%H:%M:%S
Log To Console time is ${converted-time}
Set Global Variable ${converted-time}
this script verifies that after searching the string, the result is returned then verify time is correct.
however, there is elapsed when the robot captured the current time vs the application captured time.
I cannot verify it directly, I need to give 3 seconds buffer.
robot captured time: 16:38:04
app captured time: 16:38:56
Verify Audio Time
[Arguments] ${RandomNumber}
Wait For Elements State //mark[text()='Dual-Channel-Audio-${RandomNumber}']//following::td[text()='${converted-time}']
UI which shows time

Count attempts in airflow sensor

I have a sensor that waits for a file to appear in an external file system
The sensor uses mode="reschedule"
I would like to trigger a specific behavior after X failed attempts.
Is there any straightforward way to know how many times the sensor has already attempted to run the poke method?
My quick fix so far has been to push an XCom with the attempt number, and increase it every time the poke method returns False. Is there any built-in mechanism for this?
Thank you
I had a similar problem when sensor mode = "reschedule", trying to poke a different path to a file based on the current time without directly referencing pendulum.now or datetime.now
I used task_reschedules (as done in the base sensor operator to get try_number for reschedule mode https://airflow.apache.org/docs/apache-airflow/stable/_modules/airflow/sensors/base.html#BaseSensorOperator.execute)
def execute(self, context):
task_reschedules = TaskReschedule.find_for_task_instance(context['ti'])
self.poke_number = (len(task_reschedules) + 1)
super().execute(context)
then self.poke_number can be used within poke(), and current time is approximately execution_date + (poke_number * poke_interval).
Apparently, the XCom thing isn't working, because pushed XComs don't seem to be available between pokes; they always return undefined.
try_number inside task_instance doesn't help either, as pokes don't count as a new try number
I ended up computing the attempt number by hand:
attempt_no = math.ceil((pendulum.now(tz='utc') - kwargs['ti'].start_date).seconds / kwargs['task'].poke_interval)
The code will work fine as long as individual executions of the poke method don't last longer than the poke interval (which they shouldn't)
Best

Evaluating keyword inside a for loop in robot framework

I am trying to use "exit for loop" in checking an Api availability
sleep till Rest api
FOR ${i} IN RANGE 20
Sleep 5s till rest api is available
Exit For Loop If Rest Api == True
Log to Console try again in 5 sec
END
When I try to execute this the exit for loop statement fails to recognise the Rest Api as another keyword and it throws an error like " no keyword named Exit For Loop If Rest Api ". Can we evaluate a keyword to exit from for loop instead of just variables?
Can we evaluate a keyword to exit from for loop instead of just variables?
No, you can't. The documentation clearly states that Exit for loop if requires a boolean expression. You will need to call the keyword first and save the result. You can then use the result as the expression.

Sending Array to a Single Process

I have an array with size nx*ny. The data in the array is in nrows*ncols processes. I want to send all the various parts of the array to a single array in a single process, say process 0.
I do it this way: I perform two do loops one the on nrows with variable x and another one inside that on the ncols with variable y. In each loop I find the process that has the row and coloumn same as x and y and use mpi_isend to send the data to process 0 and after that, again inside the same loop process 0 recevies the subarray by mpi_irecv.
I actually tried this and the problem is process 0 keeps receiving data that are not still sent! I even tried using mpi_barrier without success. Below is my code. Can anyone help me please? Thanks.
do x=0,grid%nrows
do y=0,grid%ncols
! Finding the relevant process and sending
if ((grid%row==x) .and. (grid%col==y)) then
call MPI_ISEND(tempp,ctot,MPI_DOUBLE_PRECISION,0, &
& grid%proc,MPI_COMM_WORLD,ierr)
end if
! Process 0 receives data
if (grid%proc==0) then
call MPI_IRECV(temp0(2*grid%xl:2*grid%xl+2*grid%mx-1, &
& :,1:size(v%a,4)), &
& ctot,MPI_DOUBLE_PRECISION, &
& x*grid%ncols+y,x*grid%ncols+y,MPI_COMM_WORLD,stat,ierr)
end if
end do
end do
mpi_Irecv and mpi_Isend are non-blocking functions. This means, that these function calls return before the transmission is completed. To solve your problem, you can either
use the blocking versions, mpi_Recv and mpi_Send or
add mpi_Wait calls to your solution to wait for the non-blocking calls to finish.

Resources